Skip to content

Commit

Permalink
Update PR
Browse files Browse the repository at this point in the history
* Add  --source-directory 'path/as/source/' --destination-directory 'path/as/destination' functionality
  • Loading branch information
abraunegg committed Oct 18, 2023
1 parent ad3ddee commit 1eff2d7
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 10 deletions.
12 changes: 8 additions & 4 deletions docs/application-config-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:**_ `onedrive --source-directory 'path/as/source/' --destination-directory 'path/as/destination'`

_**Usage Example:**_
_**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.
Expand Down
28 changes: 26 additions & 2 deletions src/config.d
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}
Expand Down
11 changes: 11 additions & 0 deletions src/main.d
Original file line number Diff line number Diff line change
Expand Up @@ -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") != "") {
Expand Down Expand Up @@ -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");
Expand Down
25 changes: 21 additions & 4 deletions src/sync.d
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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([
Expand Down

0 comments on commit 1eff2d7

Please sign in to comment.