Skip to content

Commit 0216b63

Browse files
authored
Implement FR #3107: Add config option to not set file and directory permissions (#3112)
* Implement configuration option to not set directory and file permissions
1 parent 0e7d3f1 commit 0216b63

File tree

5 files changed

+46
-9
lines changed

5 files changed

+46
-9
lines changed

docs/application-config-options.md

+12
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Before reading this document, please ensure you are running application version
1919
- [debug_https](#debug_https)
2020
- [disable_download_validation](#disable_download_validation)
2121
- [disable_notifications](#disable_notifications)
22+
- [disable_permission_set](#disable_permission_set)
2223
- [disable_upload_validation](#disable_upload_validation)
2324
- [display_running_config](#display_running_config)
2425
- [display_transfer_metrics](#display_transfer_metrics)
@@ -279,6 +280,17 @@ _**Config Example:**_ `disable_notifications = "false"` or `disable_notification
279280

280281
_**CLI Option Use:**_ `--disable-notifications`
281282

283+
### disable_permission_set
284+
_**Description:**_ This setting controls whether the application will set the permissions on files and directories using the values of 'sync_dir_permissions' and 'sync_file_permissions'. When this option is enabled, file system permission inheritance will be used to assign the permissions for your data. This option may be useful if the file system configured does not allow setting of POSIX permissions.
285+
286+
_**Value Type:**_ Boolean
287+
288+
_**Default Value:**_ False
289+
290+
_**Config Example:**_ `disable_permission_set = "false"` or `disable_permission_set = "true"`
291+
292+
_**CLI Option Use:**_ *None - this is a config file option only*
293+
282294
### disable_upload_validation
283295
_**Description:**_ This option determines whether the client will conduct integrity validation on files uploaded to Microsoft OneDrive. Sometimes, when uploading files, particularly to SharePoint, SharePoint will modify your file post upload by adding new data to your file which breaks the integrity checking of the upload performed by this client. Enable this option to disable the integrity checks performed by this client.
284296

docs/usage.md

+3
Original file line numberDiff line numberDiff line change
@@ -851,6 +851,9 @@ sync_file_permissions = "600"
851851
> [!IMPORTANT]
852852
> Please note that special permission bits such as setuid, setgid, and the sticky bit are not supported. Valid permission values range from `000` to `777` only.
853853
854+
> [!NOTE]
855+
> To prevent the application from modifying file or directory permissions and instead rely on the existing file system permission inheritance, add `disable_permission_set = "true"` to your configuration file.
856+
854857
### How are uploads and downloads managed?
855858
The system manages downloads and uploads using a multi-threaded approach. Specifically, the application utilises by default 8 threads (a maximum of 16 can be configured) for these processes. This thread count is preset and cannot be modified by users. This design ensures efficient handling of data transfers.
856859

src/config.d

+4
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,9 @@ class ApplicationConfig {
364364
// - Enable the calculation of transfer metrics (duration,speed) for the transfer of a file
365365
boolValues["display_transfer_metrics"] = false;
366366

367+
// Diable setting the permissions for directories and files, using the inherited permissions
368+
boolValues["disable_permission_set"] = false;
369+
367370
// EXPAND USERS HOME DIRECTORY
368371
// Determine the users home directory.
369372
// Need to avoid using ~ here as expandTilde() below does not interpret correctly when running under init.d or systemd scripts
@@ -1436,6 +1439,7 @@ class ApplicationConfig {
14361439
addLogEntry("Config option 'resync' = " ~ to!string(getValueBool("resync")));
14371440
addLogEntry("Config option 'resync_auth' = " ~ to!string(getValueBool("resync_auth")));
14381441
addLogEntry("Config option 'cleanup_local_files' = " ~ to!string(getValueBool("cleanup_local_files")));
1442+
addLogEntry("Config option 'disable_permission_set' = " ~ to!string(getValueBool("disable_permission_set")));
14391443
addLogEntry("Config option 'transfer_order' = " ~ getValueString("transfer_order"));
14401444

14411445
// data integrity

src/onedrive.d

+18-6
Original file line numberDiff line numberDiff line change
@@ -780,9 +780,15 @@ class OneDriveApi {
780780
try {
781781
if (debugLogging) {addLogEntry("Requested local path does not exist, creating directory structure: " ~ newPath, ["debug"]);}
782782
mkdirRecurse(newPath);
783-
// Configure the applicable permissions for the folder
784-
if (debugLogging) {addLogEntry("Setting directory permissions for: " ~ newPath, ["debug"]);}
785-
newPath.setAttributes(appConfig.returnRequiredDirectoryPermissions());
783+
// Has the user disabled the setting of filesystem permissions?
784+
if (!appConfig.getValueBool("disable_permission_set")) {
785+
// Configure the applicable permissions for the folder
786+
if (debugLogging) {addLogEntry("Setting directory permissions for: " ~ newPath, ["debug"]);}
787+
newPath.setAttributes(appConfig.returnRequiredDirectoryPermissions());
788+
} else {
789+
// Use inherited permissions
790+
if (debugLogging) {addLogEntry("Using inherited filesystem permissions for: " ~ newPath, ["debug"]);}
791+
}
786792
} catch (FileException exception) {
787793
// display the error message
788794
displayFileSystemErrorMessage(exception.msg, getFunctionName!({}));
@@ -794,9 +800,15 @@ class OneDriveApi {
794800
downloadFile(url, saveToPath, fileSize);
795801
// Does path exist?
796802
if (exists(saveToPath)) {
797-
// File was downloaded successfully - configure the applicable permissions for the file
798-
if (debugLogging) {addLogEntry("Setting file permissions for: " ~ saveToPath, ["debug"]);}
799-
saveToPath.setAttributes(appConfig.returnRequiredFilePermissions());
803+
// Has the user disabled the setting of filesystem permissions?
804+
if (!appConfig.getValueBool("disable_permission_set")) {
805+
// File was downloaded successfully - configure the applicable permissions for the file
806+
if (debugLogging) {addLogEntry("Setting file permissions for: " ~ saveToPath, ["debug"]);}
807+
saveToPath.setAttributes(appConfig.returnRequiredFilePermissions());
808+
} else {
809+
// Use inherited permissions
810+
if (debugLogging) {addLogEntry("Using inherited filesystem permissions for: " ~ newPath, ["debug"]);}
811+
}
800812
}
801813
}
802814

src/sync.d

+9-3
Original file line numberDiff line numberDiff line change
@@ -2810,9 +2810,15 @@ class SyncEngine {
28102810
if (debugLogging) {addLogEntry("Requested local path does not exist, creating directory structure: " ~ newItemPath, ["debug"]);}
28112811
mkdirRecurse(newItemPath);
28122812

2813-
// Configure the applicable permissions for the folder
2814-
if (debugLogging) {addLogEntry("Setting directory permissions for: " ~ newItemPath, ["debug"]);}
2815-
newItemPath.setAttributes(appConfig.returnRequiredDirectoryPermissions());
2813+
// Has the user disabled the setting of filesystem permissions?
2814+
if (!appConfig.getValueBool("disable_permission_set")) {
2815+
// Configure the applicable permissions for the folder
2816+
if (debugLogging) {addLogEntry("Setting directory permissions for: " ~ newItemPath, ["debug"]);}
2817+
newItemPath.setAttributes(appConfig.returnRequiredDirectoryPermissions());
2818+
} else {
2819+
// Use inherited permissions
2820+
if (debugLogging) {addLogEntry("Using inherited filesystem permissions for: " ~ newItemPath, ["debug"]);}
2821+
}
28162822

28172823
// Update the time of the folder to match the last modified time as is provided by OneDrive
28182824
// If there are any files then downloaded into this folder, the last modified time will get

0 commit comments

Comments
 (0)