Correctly set config directory permissions at first start (#1132)

* When ~/.config/onedrive/ gets created for the first time, directory permissions are not set, thus, effective permissions of 'd---------' get applied. This then causes issues attempting to update the 'refresh_token' as permission is denied.
* When permission is denied, the file exception error is not correctly handled
* Set refresh_token file permissions
This commit is contained in:
abraunegg 2020-11-09 08:06:48 +11:00 committed by GitHub
parent 7a4abfff40
commit 2c80033c89
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 1 deletions

View file

@ -664,11 +664,20 @@ final class Config
int returnRequiredDirectoryPermisions() {
// read the configuredDirectoryPermissionMode and return
if (configuredDirectoryPermissionMode == 0) {
// the configured value is zero, this means that directories would get
// values of d---------
configureRequiredDirectoryPermisions();
}
return configuredDirectoryPermissionMode;
}
int returnRequiredFilePermisions() {
// read the configuredFilePermissionMode and return
if (configuredFilePermissionMode == 0) {
// the configured value is zero
configureRequiredFilePermisions();
}
return configuredFilePermissionMode;
}
}

View file

@ -725,7 +725,14 @@ final class OneDriveApi
refreshToken = response["refresh_token"].str();
accessTokenExpiration = Clock.currTime() + dur!"seconds"(response["expires_in"].integer());
if (!.dryRun) {
std.file.write(cfg.refreshTokenFilePath, refreshToken);
try {
// try and update the refresh_token file
std.file.write(cfg.refreshTokenFilePath, refreshToken);
cfg.refreshTokenFilePath.setAttributes(cfg.returnRequiredFilePermisions());
} catch (FileException e) {
// display the error message
displayFileSystemErrorMessage(e.msg);
}
}
if (printAccessToken) writeln("New access token: ", accessToken);
} else {
@ -1310,6 +1317,14 @@ final class OneDriveApi
log.error(" Error Reason: ", errorMessage["error_description"].str);
}
}
// Parse and display error message received from the local file system
private void displayFileSystemErrorMessage(string message)
{
log.error("ERROR: The local file system returned an error with the following message:");
auto errorArray = splitLines(message);
log.error(" Error Message: ", errorArray[0]);
}
}
unittest