Fix changing permissions on pre-existing local directories (#1152)

* When attempting to create local directories, test to determine if they exist locally first before creating & setting file system permissions
This commit is contained in:
abraunegg 2020-11-20 05:36:20 +11:00 committed by GitHub
parent b163e8eff2
commit 8c23efc6c5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 12 deletions

View file

@ -658,6 +658,7 @@ int main(string[] args)
// Attempt to create the sync dir we have been configured with
mkdirRecurse(syncDir);
// Configure the applicable permissions for the folder
log.vdebug("Setting directory permissions for: ", syncDir);
syncDir.setAttributes(cfg.returnRequiredDirectoryPermisions());
} catch (std.file.FileException e) {
// Creating the sync directory failed
@ -913,6 +914,7 @@ int main(string[] args)
string singleDirectoryPath = cfg.getValueString("single_directory");
mkdirRecurse(singleDirectoryPath);
// Configure the applicable permissions for the folder
log.vdebug("Setting directory permissions for: ", singleDirectoryPath);
singleDirectoryPath.setAttributes(cfg.returnRequiredDirectoryPermisions());
}
}

View file

@ -504,23 +504,30 @@ final class OneDriveApi
}
}
// Create the directory
// Create the required local directory
string newPath = dirName(saveToPath);
try {
mkdirRecurse(newPath);
} catch (FileException e) {
// display the error message
displayFileSystemErrorMessage(e.msg);
// Does the path exist locally?
if (!exists(newPath)) {
try {
log.vdebug("Requested path does not exist, creating directory structure: ", newPath);
mkdirRecurse(newPath);
// Configure the applicable permissions for the folder
log.vdebug("Setting directory permissions for: ", newPath);
newPath.setAttributes(cfg.returnRequiredDirectoryPermisions());
} catch (FileException e) {
// display the error message
displayFileSystemErrorMessage(e.msg);
}
}
// Configure the applicable permissions for the folder
newPath.setAttributes(cfg.returnRequiredDirectoryPermisions());
const(char)[] url = driveByIdUrl ~ driveId ~ "/items/" ~ id ~ "/content?AVOverride=1";
// Download file
download(url, saveToPath, fileSize);
// Does path exist?
if (exists(saveToPath)) {
// File was downloaded sucessfully - configure the applicable permissions for the file
log.vdebug("Setting file permissions for: ", saveToPath);
saveToPath.setAttributes(cfg.returnRequiredFilePermisions());
}
}
@ -749,6 +756,7 @@ final class OneDriveApi
try {
// try and update the refresh_token file
std.file.write(cfg.refreshTokenFilePath, refreshToken);
log.vdebug("Setting file permissions for: ", cfg.refreshTokenFilePath);
cfg.refreshTokenFilePath.setAttributes(cfg.returnRequiredFilePermisions());
} catch (FileException e) {
// display the error message

View file

@ -2438,10 +2438,15 @@ final class SyncEngine
if (!dryRun) {
try {
// Create the new directory
mkdirRecurse(path);
// Configure the applicable permissions for the folder
path.setAttributes(cfg.returnRequiredDirectoryPermisions());
// Does the path exist locally?
if (!exists(path)) {
// Create the new directory
log.vdebug("Requested path does not exist, creating directory structure: ", path);
mkdirRecurse(path);
// Configure the applicable permissions for the folder
log.vdebug("Setting directory permissions for: ", path);
path.setAttributes(cfg.returnRequiredDirectoryPermisions());
}
} catch (FileException e) {
// display the error message
displayFileSystemErrorMessage(e.msg);