1
Vote

Bug in Rapi CopyFileToDevice command

description

If the active sync connection drops out part way through copying a file to the device using CopyFileToDevice, the handle to the original source file is not closed and that file is then inaccessible until the application is restarted.

The existing code only closes the handle to the remote file and not the source file.
            // write our buffer to the remote file
            if(! Convert.ToBoolean(CeWriteFile(remoteFile, buffer, bytesread, ref byteswritten, 0)))
            { // check for success
                CeCloseHandle(remoteFile);
                throw new RAPIException("Could not write to remote file");
            }
Should have localFile.Close(); added before the exception is rethrown or even better would be to have the entire use of the source file in a using clause or try/catch/finally to ensure its always closed properly.

comments