Commit 76aca390 authored by Jondy Zhao's avatar Jondy Zhao

Remove duplicate mapped drive (same share folder or subfolder).

parent 6656d35b
......@@ -138,6 +138,41 @@ netuse_map_drive(PyObject *self, PyObject *args)
return NULL;
}
static int
check_duplicate_shared_folder(PyObject *retvalue, const char *folder)
{
if (!PyList_Check(retvalue))
return -1;
Py_ssize_t size = PyList_Size(retvalue);
int len = strlen(folder);
int len2;
PyObject *item;
char * s;
while (size) {
size --;
item = PySequence_GetItem(retvalue, size);
if (!PySequence_Check(item))
return -1;
s = PyString_AsString(PySequence_GetItem(item, 1));
if (s == NULL)
return -1;
len2 = strlen(s);
if (strncmp(folder, s, len > len2 ? len : len2) == 0) {
if (len2 > len) {
if (PySequence_DelItem(retvalue, size) == -1)
return -1;
size --;
}
else
return 1;
}
}
return 0;
}
static PyObject *
netuse_usage_report(PyObject *self, PyObject *args)
{
......@@ -227,6 +262,16 @@ netuse_usage_report(PyObject *self, PyObject *args)
return NULL;
}
switch (check_duplicate_shared_folder(retvalue, szRemoteName)) {
case -1:
Py_XDECREF(retvalue);
return NULL;
case 1:
continue;
default:
break;
}
if (GetDiskFreeSpaceEx(drivepath,
&lFreeBytesAvailable,
&lTotalNumberOfBytes,
......@@ -254,7 +299,6 @@ netuse_usage_report(PyObject *self, PyObject *args)
return NULL;
}
}
return retvalue;
}
......
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