Update PR

* Add  --source-directory 'path/as/source/' --destination-directory 'path/as/destination' functionality
This commit is contained in:
abraunegg 2023-10-18 19:15:27 +11:00
parent ad3ddee0ec
commit 1eff2d7d67
4 changed files with 66 additions and 10 deletions

View file

@ -873,9 +873,11 @@ _**Usage Example:**_ `onedrive --create-share-link 'relative/path/to/your/file.t
_**Additional Usage Notes:**_ If writable access to the file is required, you must add `--with-editing-perms` to your command. See below for details.
### CLI Option: --destination-directory
_**Description:**_
_**Description:**_ This CLI option specifies the 'destination' portion of moving a file or folder online, without performing a sync operation.
_**Usage Example:**_
_**Usage Example:**_ `onedrive --source-directory 'path/as/source/' --destination-directory 'path/as/destination'`
_**Additional Usage Notes:**_ All specified paths are relative to your configured 'sync_dir'.
### CLI Option: --display-config
_**Description:**_ This CLI option will display the effective application configuration
@ -968,9 +970,11 @@ _**Usage Example:**_ `onedrive --sync --single-directory 'Data'`
_**Additional Usage Notes:**_ The path specified is relative to your configured 'sync_dir' path. If the physical local path 'Folder' to sync is `~/OneDrive/Data/Folder` then the command would be `--single-directory 'Data/Folder'`.
### CLI Option: --source-directory
_**Description:**_
_**Description:**_ This CLI option specifies the 'source' portion of moving a file or folder online, without performing a sync operation.
_**Usage Example:**_
_**Usage Example:**_ `onedrive --source-directory 'path/as/source/' --destination-directory 'path/as/destination'`
_**Additional Usage Notes:**_ All specified paths are relative to your configured 'sync_dir'.
### CLI Option: --sync | -s
_**Description:**_ This CLI option controls the 'Standalone Mode' operational aspect of the client. When this option is used, the client will perform a one-time sync of data between Microsoft OneDrive and your local system.

View file

@ -1986,9 +1986,9 @@ class ApplicationConfig {
operationalConflictDetected = true;
}
// --get-O365-drive-id cannot be used with --resync and/or --resync-auth
// --get-sharepoint-drive-id cannot be used with --resync and/or --resync-auth
if ((!getValueString("sharepoint_library_name").empty) && ((getValueBool("resync")) || (getValueBool("resync_auth")))) {
log.error("ERROR: --get-O365-drive-id cannot be used with --resync or --resync-auth.");
log.error("ERROR: --get-sharepoint-drive-id cannot be used with --resync or --resync-auth.");
operationalConflictDetected = true;
}
@ -2060,6 +2060,30 @@ class ApplicationConfig {
operationalConflictDetected = true;
}
// --monitor and --source-directory cannot be used together
if ((getValueBool("monitor")) && (!getValueString("source_directory").empty)) {
log.error("ERROR: --monitor and --source-directory cannot be used together.");
operationalConflictDetected = true;
}
// --sync and --source-directory cannot be used together
if ((getValueBool("synchronize")) && (!getValueString("source_directory").empty)) {
log.error("ERROR: --sync and --source-directory cannot be used together.");
operationalConflictDetected = true;
}
// --monitor and --destination-directory cannot be used together
if ((getValueBool("monitor")) && (!getValueString("destination_directory").empty)) {
log.error("ERROR: --monitor and --destination-directory cannot be used together.");
operationalConflictDetected = true;
}
// --sync and --destination-directory cannot be used together
if ((getValueBool("synchronize")) && (!getValueString("destination_directory").empty)) {
log.error("ERROR: --sync and --destination-directory cannot be used together.");
operationalConflictDetected = true;
}
// Return bool value indicating if we have an operational conflict
return operationalConflictDetected;
}

View file

@ -400,6 +400,7 @@ int main(string[] cliArgs) {
// - Are we createing a shareable link for an existing file on OneDrive?
// - Are we just creating a directory online, without any sync being performed?
// - Are we just deleting a directory online, without any sync being performed?
// - Are we renaming or moving a directory?
// --get-sharepoint-drive-id - Get the SharePoint Library drive_id
if (appConfig.getValueString("sharepoint_library_name") != "") {
@ -477,6 +478,16 @@ int main(string[] cliArgs) {
return EXIT_SUCCESS;
}
// Are we renaming or moving a directory?
// onedrive --source-directory 'path/as/source/' --destination-directory 'path/as/destination'
if ((appConfig.getValueString("source_directory") != "") && (appConfig.getValueString("destination_directory") != "")) {
// We are renaming or moving a directory
syncEngineInstance.uploadMoveItem(appConfig.getValueString("source_directory"), appConfig.getValueString("destination_directory"));
// Exit application
// Use exit scopes to shutdown API
return EXIT_SUCCESS;
}
// If we get to this point, we have not performed a 'no-sync' task ..
log.error("\nYour command line input is missing either the '--sync' or '--monitor' switches. Please include one (but not both) of these switches in your command line, or refer to 'onedrive --help' for additional guidance.\n");
log.error("It is important to note that you must include one of these two arguments in your command line for the application to perform a synchronisation with Microsoft OneDrive\n");

View file

@ -2947,6 +2947,12 @@ class SyncEngine {
// Return a true|false response
bool clientSideRuleExcludesPath = false;
// does the path exist?
if (!exists(localFilePath)) {
// path does not exist - we cant review any client side rules on something that does not exist locally
return clientSideRuleExcludesPath;
}
// - check_nosync
if (!clientSideRuleExcludesPath) {
@ -6246,7 +6252,7 @@ class SyncEngine {
if (!itemInDB) {
// path to delete is not in the local database ..
// was this a --remove-directory attempt?
if ((appConfig.getValueString("remove_directory") != "")) {
if (!appConfig.getValueBool("monitor")) {
// --remove-directory deletion attempt
log.error("The item to delete is not in the local database - unable to delete online");
return;
@ -6357,12 +6363,23 @@ class SyncEngine {
}
} else {
if (!exists(newPath)) {
log.vlog("uploadMoveItem target has disappeared: ", newPath);
return;
// is this --monitor use?
if (appConfig.getValueBool("monitor")) {
log.vlog("uploadMoveItem target has disappeared: ", newPath);
return;
}
}
// Configure the modification JSON item
SysTime mtime = timeLastModified(newPath).toUTC();
SysTime mtime;
if (appConfig.getValueBool("monitor")) {
// Use the newPath modified timestamp
mtime = timeLastModified(newPath).toUTC();
} else {
// Use the current system time
mtime = Clock.currTime().toUTC();
}
JSONValue data = [
"name": JSONValue(baseName(newPath)),
"parentReference": JSONValue([