Add ability to skip symlinks (Issue #87) (#92)

* Add ability to skip symlinks
This commit is contained in:
Leif Denby 2018-08-02 21:02:10 +01:00 committed by abraunegg
parent 8c2629e90c
commit c0074638da
4 changed files with 25 additions and 4 deletions

View file

@ -194,6 +194,7 @@ This file does not get created by default, and should only be created if you wan
Available options:
* `sync_dir`: directory where the files will be synced
* `skip_file`: any files or directories that match this pattern will be skipped during sync.
* `skip_symlinks`: any files or directories that are symlinked will be skipped during sync
### sync_dir
Example: `sync_dir="~/MyDirToSync"`
@ -210,6 +211,11 @@ Patterns are case insensitive. `*` and `?` [wildcards characters](https://techne
**Note:** after changing `skip_file`, you must perform a full synchronization by executing `onedrive --resync`
### skip_symlinks
Example: `skip_symlinks = "true"`
Setting this to `"true"` will skip all symlinks while syncing.
### Selective sync
Selective sync allows you to sync only specific files and directories.
To enable selective sync create a file named `sync_list` in `~/.config/onedrive`.

View file

@ -30,6 +30,9 @@ final class Config
// Configure to skip ONLY temp files (~*.doc etc) by default
// Prior configuration was: .*|~*
setValue("skip_file", "~*");
// By default symlinks are not skipped (using string type
// instead of boolean because hashmap only stores string types)
setValue("skip_symlinks", "false");
if (!load(userConfigFilePath)) {
log.vlog("No config file found, using defaults");
}

View file

@ -58,6 +58,8 @@ int main(string[] args)
bool uploadOnly;
// Add a check mounts option to resolve https://github.com/abraunegg/onedrive/issues/8
bool checkMount;
// Add option to skip symlinks
bool skipSymlinks;
try {
auto opt = getopt(
@ -77,6 +79,7 @@ int main(string[] args)
"resync", "Forget the last saved state, perform a full sync", &resync,
"remove-directory", "Remove a directory on OneDrive - no sync will be performed.", &removeDirectory,
"single-directory", "Specify a single local directory within the OneDrive root to sync.", &singleDirectory,
"skip-symlinks", "Skip syncing of symlinks", &skipSymlinks,
"source-directory", "Source directory to rename or move on OneDrive - no sync will be performed.", &sourceDirectory,
"syncdir", "Set the directory used to sync the files that are synced", &syncDirName,
"synchronize", "Perform a synchronization", &synchronize,
@ -119,6 +122,7 @@ int main(string[] args)
// command line parameters override the config
if (syncDirName) cfg.setValue("sync_dir", syncDirName.expandTilde().absolutePath());
if (skipSymlinks) cfg.setValue("skip_symlinks", "true");
// upgrades
if (exists(configDirName ~ "/items.db")) {

View file

@ -933,10 +933,18 @@ final class SyncEngine
if(encodeComponent(path).length < maxPathLength){
// path is less than maxPathLength
// skip unexisting symbolic links
if (isSymlink(path) && !exists(readLink(path))) {
log.vlog("Skipping item - symbolic link: ", path);
return;
if (isSymlink(path)) {
// if config says so we skip all symlinked items
if (cfg.getValue("skip_symlinks") == "true") {
log.vlog("Skipping item - skip symbolic links configured: ", path);
return;
}
// skip unexisting symbolic links
else if (!exists(readLink(path))) {
log.vlog("Skipping item - invalid symbolic link: ", path);
return;
}
}
// Restriction and limitations about windows naming files