aboutsummaryrefslogtreecommitdiffstats
path: root/drive/sync_download.go
diff options
context:
space:
mode:
authorPetter Rasmussen2016-02-03 20:52:51 +0100
committerPetter Rasmussen2016-02-03 20:52:51 +0100
commit5f1972a0d689b9965fc3fb9f5b9a5f9487fb0f46 (patch)
tree562be8bd3843de3c9bdeb5099c9ec62211ec55d1 /drive/sync_download.go
parent6d0a23e4bdf5ffa36cecb2cb85a6291f9235f619 (diff)
downloadgdrive-5f1972a0d689b9965fc3fb9f5b9a5f9487fb0f46.tar.bz2
Add dry-run flag for syncing
Diffstat (limited to 'drive/sync_download.go')
-rw-r--r--drive/sync_download.go21
1 files changed, 21 insertions, 0 deletions
diff --git a/drive/sync_download.go b/drive/sync_download.go
index 37c78cb..ba86aae 100644
--- a/drive/sync_download.go
+++ b/drive/sync_download.go
@@ -16,6 +16,7 @@ type DownloadSyncArgs struct {
Progress io.Writer
RootId string
Path string
+ DryRun bool
DeleteExtraneous bool
}
@@ -104,6 +105,11 @@ func (self *Drive) createMissingLocalDirs(files *syncFiles, args DownloadSyncArg
return nil, fmt.Errorf("Failed to determine local absolute path: %s", err)
}
fmt.Fprintf(args.Out, "[%04d/%04d] Creating directory: %s\n", i + 1, missingCount, path)
+
+ if args.DryRun {
+ continue
+ }
+
mkdir(path)
}
@@ -125,6 +131,11 @@ func (self *Drive) downloadMissingFiles(files *syncFiles, args DownloadSyncArgs)
return fmt.Errorf("Failed to determine local absolute path: %s", err)
}
fmt.Fprintf(args.Out, "[%04d/%04d] Downloading %s -> %s\n", i + 1, missingCount, remotePath, localPath)
+
+ if args.DryRun {
+ continue
+ }
+
err = self.downloadRemoteFile(rf.file.Id, localPath, args)
if err != nil {
return err
@@ -149,6 +160,11 @@ func (self *Drive) downloadChangedFiles(files *syncFiles, args DownloadSyncArgs)
return fmt.Errorf("Failed to determine local absolute path: %s", err)
}
fmt.Fprintf(args.Out, "[%04d/%04d] Downloading %s -> %s\n", i + 1, changedCount, remotePath, localPath)
+
+ if args.DryRun {
+ continue
+ }
+
err = self.downloadRemoteFile(cf.remote.file.Id, localPath, args)
if err != nil {
return err
@@ -206,6 +222,11 @@ func (self *Drive) deleteExtraneousLocalFiles(files *syncFiles, args DownloadSyn
for i, lf := range extraneousFiles {
fmt.Fprintf(args.Out, "[%04d/%04d] Deleting %s\n", i + 1, extraneousCount, lf.absPath)
+
+ if args.DryRun {
+ continue
+ }
+
err := os.Remove(lf.absPath)
if err != nil {
return fmt.Errorf("Failed to delete local file: %s", err)