Resolve Correctly handle file case sensitivity issues in same folder (Issue #146) (#147)

* Resolve to correctly handle file case sensitivity issues in same folder by using the same mechanism as Issue #139
This commit is contained in:
abraunegg 2018-08-27 13:11:56 +10:00 committed by GitHub
parent b2c9e041be
commit ce311db18d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1090,7 +1090,7 @@ final class SyncEngine
JSONValue response; JSONValue response;
// test if the path we are going to create already exists on OneDrive // test if the path we are going to create already exists on OneDrive
try { try {
response = onedrive.getPathDetails(path); response = onedrive.getPathDetails(path);
} catch (OneDriveException e) { } catch (OneDriveException e) {
if (e.httpStatusCode == 404) { if (e.httpStatusCode == 404) {
// The directory was not found // The directory was not found
@ -1265,49 +1265,63 @@ final class SyncEngine
} }
} }
log.vlog("Requested file to upload exists on OneDrive - local database is out of sync for this file: ", path); // Check that the filename that is returned is actually the file we wish to upload
// https://docs.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file
// Do not assume case sensitivity. For example, consider the names OSCAR, Oscar, and oscar to be the same,
// even though some file systems (such as a POSIX-compliant file system) may consider them as different.
// Note that NTFS supports POSIX semantics for case sensitivity but this is not the default behavior.
// Is the local file newer than the uploaded file? if (fileDetailsFromOneDrive["name"].str == baseName(path)){
SysTime localFileModifiedTime = timeLastModified(path).toUTC(); // OneDrive 'name' matches local path name
SysTime remoteFileModifiedTime = SysTime.fromISOExtString(fileDetailsFromOneDrive["fileSystemInfo"]["lastModifiedDateTime"].str); log.vlog("Requested file to upload exists on OneDrive - local database is out of sync for this file: ", path);
localFileModifiedTime.fracSecs = Duration.zero;
if (localFileModifiedTime > remoteFileModifiedTime){
// local file is newer
log.vlog("Requested file to upload is newer than existing file on OneDrive");
write("Uploading file ", path, " ...");
JSONValue response;
if (accountType == "personal"){ // Is the local file newer than the uploaded file?
// OneDrive Personal account upload handling SysTime localFileModifiedTime = timeLastModified(path).toUTC();
if (getSize(path) <= thresholdFileSize) { SysTime remoteFileModifiedTime = SysTime.fromISOExtString(fileDetailsFromOneDrive["fileSystemInfo"]["lastModifiedDateTime"].str);
response = onedrive.simpleUpload(path, parent.driveId, parent.id, baseName(path)); localFileModifiedTime.fracSecs = Duration.zero;
writeln(" done.");
if (localFileModifiedTime > remoteFileModifiedTime){
// local file is newer
log.vlog("Requested file to upload is newer than existing file on OneDrive");
write("Uploading file ", path, " ...");
JSONValue response;
if (accountType == "personal"){
// OneDrive Personal account upload handling
if (getSize(path) <= thresholdFileSize) {
response = onedrive.simpleUpload(path, parent.driveId, parent.id, baseName(path));
writeln(" done.");
} else {
writeln("");
response = session.upload(path, parent.driveId, parent.id, baseName(path));
writeln(" done.");
}
string id = response["id"].str;
string cTag = response["cTag"].str;
SysTime mtime = timeLastModified(path).toUTC();
// use the cTag instead of the eTag because Onedrive may update the metadata of files AFTER they have been uploaded
uploadLastModifiedTime(parent.driveId, id, cTag, mtime);
} else { } else {
// OneDrive Business account upload handling
writeln(""); writeln("");
response = session.upload(path, parent.driveId, parent.id, baseName(path)); response = session.upload(path, parent.driveId, parent.id, baseName(path));
writeln(" done."); writeln(" done.");
saveItem(response);
} }
string id = response["id"].str;
string cTag = response["cTag"].str; // Log action to log file
SysTime mtime = timeLastModified(path).toUTC(); log.fileOnly("Uploading file ", path, " ... done.");
// use the cTag instead of the eTag because Onedrive may update the metadata of files AFTER they have been uploaded
uploadLastModifiedTime(parent.driveId, id, cTag, mtime);
} else { } else {
// OneDrive Business account upload handling // Save the details of the file that we got from OneDrive
writeln(""); log.vlog("Updating the local database with details for this file: ", path);
response = session.upload(path, parent.driveId, parent.id, baseName(path)); saveItem(fileDetailsFromOneDrive);
writeln(" done.");
saveItem(response);
} }
// Log action to log file
log.fileOnly("Uploading file ", path, " ... done.");
} else { } else {
// Save the details of the file that we got from OneDrive // The files are the "same" name wise but different in case sensitivity
log.vlog("Updating the local database with details for this file: ", path); log.error("ERROR: A local file has the same name as another local file.");
saveItem(fileDetailsFromOneDrive); log.error("ERROR: To resolve, rename this local file: ", absolutePath(path));
log.log("Skipping uploading this new file: ", absolutePath(path));
} }
} else { } else {
// Skip file - too large // Skip file - too large