Comment 62 for bug 365881

Revision history for this message
William Bass (webdunce) wrote :

Ray,

I don't know windows api either. I found SetErrorMode after literally hours and hours of googling. Also, it needs to be clear...I have no experience in Python at all...except to try to figure out the Wubi code.

Also, you raise a good point, I seem to recall getting this error during installation, too. So, turning the message off just during Drive instantiation is probably not going to prevent all cases of this message.

In that case, I guess the script is calling methods on Drive objects somewhere else? So the SetErrorMode should be incorporated directly in the Drive methods causing the problem (get_space and get_filesystem).

However, then there is the glob.glob(path) issue that Ray Folwell found, and I see some calls to os.path.exists() in the code, too. I have confirmed taht os.path.exists() can raise the error IF it is called on an empty drive (I cannot tell if wubi code ever calls os.path.exists() on empty drives, though...but the potential seems to be there).

I recommend something else, in this case....

Somewhere in the Wubi code, there needs to be a function like so....

    def perform_disk_operation(disk_operation, *args):
        ctypes.windll.kernel32.SetErrorMode(1) # turn off no disk error
        retval = disk_operation(*args)
        ctypes.windll.kernel32.SetErrorMode(0) # restore no disk error to default mode
        return retval

Calls to the above function would actually pass in the desired function and arguments for that functions. For example...

    def get_space(self):
        drive_path = self.path
        freeuser = ctypes.c_int64()
        total = ctypes.c_int64()
        free = ctypes.c_int64()
        perform_disk_operation(ctypes.windll.kernel32.GetDiskFreeSpaceExW,
                unicode(drive_path),
                ctypes.byref(freeuser),
                ctypes.byref(total),
                ctypes.byref(free)) # FYI, returns 0 if unsuccessful...which could be
                                           # stored in a variable like so: is_successful = perform_disk_operation(....
        return total.value, freeuser.value

I don't know enough about Python to know if self needs to be an argument in the function or not {i.e., perform_disk_operation(self, disk_operation, *args): ???}, but I am envisioning a static method (does Python have those?) accessible from anywhere...perhaps in the Drive class....Drive.perform_disk_operation().

If Python doesn't support static methods, then a Disk_Manager or WubiUtilities object class could be created and instantiated and it could be used mainly for these sorts of things.

utilities = WubiUtilities
utilities.perform_disk_operation(xxx, yyy, zzz, ddd)

-----------------

Alternately (and I don't know how recommended this would be), SetErrorMode(1) could be called at the very beginning of the wubi execution and SetErrorMode(0) when wubi terminates. That would put the error mode in a non-default state while wubi is executing, and I don't know if that could cause potential problems in other windows processes or not (seems doubtful, though). It should be really easy to implement though and should prevent the pop-up the whole time (unless other windows processes are able to turn it on, which is a possibility). I would prefer to turn it off only when I am doing something that could trigger it and turn it right back on when I am done, but I thought I'd throw out the possibility anyways even though I don't favor it.