diff options
| author | Petter Rasmussen | 2016-02-21 15:05:08 +0100 |
|---|---|---|
| committer | Petter Rasmussen | 2016-02-21 15:06:08 +0100 |
| commit | 2a3b8bd5d5aad1ace85d825cbddc2bf79db28e61 (patch) | |
| tree | d44504ac5f942966cc500f19ad690f642dc92c13 | |
| parent | 4b95496643d36184ffa1a7b78ae2d1150ecdf0b6 (diff) | |
| download | gdrive-2a3b8bd5d5aad1ace85d825cbddc2bf79db28e61.tar.bz2 | |
Prevent upload to sync dirs
| -rw-r--r-- | drive/sync.go | 10 | ||||
| -rw-r--r-- | drive/upload.go | 12 |
2 files changed, 22 insertions, 0 deletions
diff --git a/drive/sync.go b/drive/sync.go index 204e7c2..2124f8f 100644 --- a/drive/sync.go +++ b/drive/sync.go @@ -73,6 +73,16 @@ func (self *Drive) prepareSyncFiles(localPath string, root *drive.File, cmp File }, nil } +func (self *Drive) isSyncFile(id string) (bool, error) { + f, err := self.service.Files.Get(id).Fields("appProperties").Do() + if err != nil { + return false, fmt.Errorf("Failed to get file: %s", err) + } + + _, ok := f.AppProperties["sync"] + return ok, nil +} + func prepareLocalFiles(root string) ([]*LocalFile, error) { var files []*LocalFile diff --git a/drive/upload.go b/drive/upload.go index 2b8c7c3..0bbc014 100644 --- a/drive/upload.go +++ b/drive/upload.go @@ -29,6 +29,18 @@ func (self *Drive) Upload(args UploadArgs) error { return fmt.Errorf("Chunk size is to big, max chunk size for this computer is %d", intMax() - 1) } + // Ensure that none of the parents are sync dirs + for _, parent := range args.Parents { + isSyncDir, err := self.isSyncFile(parent) + if err != nil { + return err + } + + if isSyncDir { + return fmt.Errorf("%s is a sync directory, use 'sync upload' instead", parent) + } + } + if args.Recursive { return self.uploadRecursive(args) } |
