mirror of
https://github.com/abraunegg/onedrive
synced 2024-05-22 23:52:13 +02:00
Fix download failure and crash due to incorrect local filesystem permissions when using mounted external devices (#1140)
* Fix download failure due to incorrect local filesystem mount permissions
This commit is contained in:
commit
0d5b004696
|
@ -493,15 +493,36 @@ final class OneDriveApi
|
||||||
{
|
{
|
||||||
checkAccessTokenExpired();
|
checkAccessTokenExpired();
|
||||||
scope(failure) {
|
scope(failure) {
|
||||||
if (exists(saveToPath)) remove(saveToPath);
|
if (exists(saveToPath)) {
|
||||||
|
// try and remove the file, catch error
|
||||||
|
try {
|
||||||
|
remove(saveToPath);
|
||||||
|
} catch (FileException e) {
|
||||||
|
// display the error message
|
||||||
|
displayFileSystemErrorMessage(e.msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the directory
|
// Create the directory
|
||||||
string newPath = dirName(saveToPath);
|
string newPath = dirName(saveToPath);
|
||||||
mkdirRecurse(newPath);
|
try {
|
||||||
|
mkdirRecurse(newPath);
|
||||||
|
} catch (FileException e) {
|
||||||
|
// display the error message
|
||||||
|
displayFileSystemErrorMessage(e.msg);
|
||||||
|
}
|
||||||
|
|
||||||
// Configure the applicable permissions for the folder
|
// Configure the applicable permissions for the folder
|
||||||
newPath.setAttributes(cfg.returnRequiredDirectoryPermisions());
|
newPath.setAttributes(cfg.returnRequiredDirectoryPermisions());
|
||||||
const(char)[] url = driveByIdUrl ~ driveId ~ "/items/" ~ id ~ "/content?AVOverride=1";
|
const(char)[] url = driveByIdUrl ~ driveId ~ "/items/" ~ id ~ "/content?AVOverride=1";
|
||||||
|
// Download file
|
||||||
download(url, saveToPath, fileSize);
|
download(url, saveToPath, fileSize);
|
||||||
|
// Does path exist?
|
||||||
|
if (exists(saveToPath)) {
|
||||||
|
// File was downloaded sucessfully - configure the applicable permissions for the file
|
||||||
|
saveToPath.setAttributes(cfg.returnRequiredFilePermisions());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_put_content
|
// https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_put_content
|
||||||
|
@ -818,8 +839,6 @@ final class OneDriveApi
|
||||||
// close open file
|
// close open file
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
// Configure the applicable permissions for the file
|
|
||||||
filename.setAttributes(cfg.returnRequiredFilePermisions());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
http.method = HTTP.Method.get;
|
http.method = HTTP.Method.get;
|
||||||
|
|
65
src/sync.d
65
src/sync.d
|
@ -2006,25 +2006,31 @@ final class SyncEngine
|
||||||
// - full path + combination of any above two - /path/name*.txt
|
// - full path + combination of any above two - /path/name*.txt
|
||||||
// - full path to file - /path/to/file.txt
|
// - full path to file - /path/to/file.txt
|
||||||
|
|
||||||
// need to compute the full path for this file
|
// is the parent id in the database?
|
||||||
path = itemdb.computePath(item.driveId, item.parentId) ~ "/" ~ item.name;
|
if (itemdb.idInLocalDatabase(item.driveId, item.parentId)){
|
||||||
|
// need to compute the full path for this file
|
||||||
// The path that needs to be checked needs to include the '/'
|
path = itemdb.computePath(item.driveId, item.parentId) ~ "/" ~ item.name;
|
||||||
// This due to if the user has specified in skip_file an exclusive path: '/path/file' - that is what must be matched
|
|
||||||
if (!startsWith(path, "/")){
|
// The path that needs to be checked needs to include the '/'
|
||||||
// Add '/' to the path
|
// This due to if the user has specified in skip_file an exclusive path: '/path/file' - that is what must be matched
|
||||||
path = '/' ~ path;
|
if (!startsWith(path, "/")){
|
||||||
|
// Add '/' to the path
|
||||||
|
path = '/' ~ path;
|
||||||
|
}
|
||||||
|
|
||||||
|
log.vdebug("skip_file item to check: ", path);
|
||||||
|
unwanted = selectiveSync.isFileNameExcluded(path);
|
||||||
|
log.vdebug("Result: ", unwanted);
|
||||||
|
if (unwanted) log.vlog("Skipping item - excluded by skip_file config: ", item.name);
|
||||||
|
} else {
|
||||||
|
// parent id is not in the database
|
||||||
|
unwanted = true;
|
||||||
|
log.vlog("Skipping file - parent path not present in local database");
|
||||||
}
|
}
|
||||||
|
|
||||||
log.vdebug("skip_file item to check: ", path);
|
|
||||||
unwanted = selectiveSync.isFileNameExcluded(path);
|
|
||||||
log.vdebug("Result: ", unwanted);
|
|
||||||
if (unwanted) log.vlog("Skipping item - excluded by skip_file config: ", item.name);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// check the item type
|
// check the item type
|
||||||
|
|
||||||
if (!unwanted) {
|
if (!unwanted) {
|
||||||
if (isItemFile(driveItem)) {
|
if (isItemFile(driveItem)) {
|
||||||
log.vdebug("The item we are syncing is a file");
|
log.vdebug("The item we are syncing is a file");
|
||||||
|
@ -2238,6 +2244,14 @@ final class SyncEngine
|
||||||
}
|
}
|
||||||
// What was the item that was saved
|
// What was the item that was saved
|
||||||
log.vdebug("item details: ", item);
|
log.vdebug("item details: ", item);
|
||||||
|
} else {
|
||||||
|
// flag was tripped, which was it
|
||||||
|
if (downloadFailed) {
|
||||||
|
log.vdebug("Download or creation of local directory failed");
|
||||||
|
}
|
||||||
|
if (malwareDetected) {
|
||||||
|
log.vdebug("OneDrive reported that file contained malware");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2423,10 +2437,18 @@ final class SyncEngine
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!dryRun) {
|
if (!dryRun) {
|
||||||
// Create the new directory
|
try {
|
||||||
mkdirRecurse(path);
|
// Create the new directory
|
||||||
// Configure the applicable permissions for the folder
|
mkdirRecurse(path);
|
||||||
path.setAttributes(cfg.returnRequiredDirectoryPermisions());
|
// Configure the applicable permissions for the folder
|
||||||
|
path.setAttributes(cfg.returnRequiredDirectoryPermisions());
|
||||||
|
} catch (FileException e) {
|
||||||
|
// display the error message
|
||||||
|
displayFileSystemErrorMessage(e.msg);
|
||||||
|
// flag that this failed
|
||||||
|
downloadFailed = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// we dont create the directory, but we need to track that we 'faked it'
|
// we dont create the directory, but we need to track that we 'faked it'
|
||||||
idsFaked ~= [item.driveId, item.id];
|
idsFaked ~= [item.driveId, item.id];
|
||||||
|
@ -2565,7 +2587,6 @@ final class SyncEngine
|
||||||
log.vdebug("onedrive.downloadById(item.driveId, item.id, path, fileSize); generated a OneDriveException");
|
log.vdebug("onedrive.downloadById(item.driveId, item.id, path, fileSize); generated a OneDriveException");
|
||||||
// 408 = Request Time Out
|
// 408 = Request Time Out
|
||||||
// 429 = Too Many Requests - need to delay
|
// 429 = Too Many Requests - need to delay
|
||||||
|
|
||||||
if (e.httpStatusCode == 408) {
|
if (e.httpStatusCode == 408) {
|
||||||
// 408 error handling - request time out
|
// 408 error handling - request time out
|
||||||
// https://github.com/abraunegg/onedrive/issues/694
|
// https://github.com/abraunegg/onedrive/issues/694
|
||||||
|
@ -2637,6 +2658,12 @@ final class SyncEngine
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (FileException e) {
|
||||||
|
// There was a file system error
|
||||||
|
// display the error message
|
||||||
|
displayFileSystemErrorMessage(e.msg);
|
||||||
|
downloadFailed = true;
|
||||||
|
return;
|
||||||
} catch (std.exception.ErrnoException e) {
|
} catch (std.exception.ErrnoException e) {
|
||||||
// There was a file system error
|
// There was a file system error
|
||||||
// display the error message
|
// display the error message
|
||||||
|
|
Loading…
Reference in a new issue