Commit 33494024 authored by Jondy Zhao's avatar Jondy Zhao

Do not retrieve TotalNumberOfFreeBytes to improve performance.

parent ba04f114
...@@ -137,7 +137,21 @@ netuse_map_drive(PyObject *self, PyObject *args) ...@@ -137,7 +137,21 @@ netuse_map_drive(PyObject *self, PyObject *args)
PyErr_SetString(PyExc_RuntimeError, "Not Implemented"); PyErr_SetString(PyExc_RuntimeError, "Not Implemented");
return NULL; return NULL;
} }
/*
* Travel all the mapped drive to check whether there is duplicated
* shared folder:
*
* Return 1 if current share folder is same or sub-folder of the
* mapped folder;
*
* Return -1 if unknown exception occurs;
*
* Remove mapped item from list if the mapped folder is sub-folder
* of current share folder.
*
* Return 0 if it's new share folder.
*
*/
static int static int
check_duplicate_shared_folder(PyObject *retvalue, const char *folder) check_duplicate_shared_folder(PyObject *retvalue, const char *folder)
{ {
...@@ -150,7 +164,7 @@ check_duplicate_shared_folder(PyObject *retvalue, const char *folder) ...@@ -150,7 +164,7 @@ check_duplicate_shared_folder(PyObject *retvalue, const char *folder)
PyObject *item; PyObject *item;
char * s; char * s;
while (size) { while (size > 0) {
size --; size --;
item = PySequence_GetItem(retvalue, size); item = PySequence_GetItem(retvalue, size);
if (!PySequence_Check(item)) if (!PySequence_Check(item))
...@@ -275,13 +289,12 @@ netuse_usage_report(PyObject *self, PyObject *args) ...@@ -275,13 +289,12 @@ netuse_usage_report(PyObject *self, PyObject *args)
if (GetDiskFreeSpaceEx(drivepath, if (GetDiskFreeSpaceEx(drivepath,
&lFreeBytesAvailable, &lFreeBytesAvailable,
&lTotalNumberOfBytes, &lTotalNumberOfBytes,
&lTotalNumberOfFreeBytes NULL
)) { )) {
PyObject *pobj = Py_BuildValue("ssLLL", PyObject *pobj = Py_BuildValue("ssLLL",
drivename, drivename,
szRemoteName, szRemoteName,
lFreeBytesAvailable, lFreeBytesAvailable,
lTotalNumberOfFreeBytes,
lTotalNumberOfBytes lTotalNumberOfBytes
); );
if (PyList_Append(retvalue, pobj) == -1) { if (PyList_Append(retvalue, pobj) == -1) {
...@@ -329,7 +342,7 @@ static PyMethodDef NetUseMethods[] = { ...@@ -329,7 +342,7 @@ static PyMethodDef NetUseMethods[] = {
( (
"usagereport(servername='')\n\n" "usagereport(servername='')\n\n"
"Return a tuple to report all the net drive information:\n" "Return a tuple to report all the net drive information:\n"
"(drive, remote, available, free, total).\n" "[ (drive, remote, available, total), ... ]\n"
"If servername is not empty, then only net drives in the specified server\n" "If servername is not empty, then only net drives in the specified server\n"
"are returned.\n" "are returned.\n"
) )
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment