From 2a3b8bd5d5aad1ace85d825cbddc2bf79db28e61 Mon Sep 17 00:00:00 2001 From: Petter Rasmussen Date: Sun, 21 Feb 2016 15:05:08 +0100 Subject: Prevent upload to sync dirs --- drive/sync.go | 10 ++++++++++ drive/upload.go | 12 ++++++++++++ 2 files changed, 22 insertions(+) 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) } -- cgit v1.2.3