From bc19e2d84b8c3c46cba4711cc9af26641f140b2f Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Thu, 20 Aug 2015 18:36:06 +0100 Subject: [PATCH] dropbox: Issue an error message when trying to upload bad file name - fixes #108 --- docs/content/dropbox.md | 6 ++++++ dropbox/dropbox.go | 12 +++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/docs/content/dropbox.md b/docs/content/dropbox.md index fa2e41cdf..c95521f1b 100644 --- a/docs/content/dropbox.md +++ b/docs/content/dropbox.md @@ -80,3 +80,9 @@ MD5SUMs so syncs will effectively have the `--size-only` flag set. Note that Dropbox is case sensitive so you can't have a file called "Hello.doc" and one called "hello.doc". + +There are some file names such as `thumbs.db` which Dropbox can't +store. There is a full list of them in the ["Ignored Files" section +of this document](https://www.dropbox.com/en/help/145). Rclone will +issue an error message `File name disallowed - not uploading` if it +attempt to upload one of those file names, but the sync won't fail. diff --git a/dropbox/dropbox.go b/dropbox/dropbox.go index f327bba62..077dd6f29 100644 --- a/dropbox/dropbox.go +++ b/dropbox/dropbox.go @@ -36,6 +36,7 @@ import ( "io/ioutil" "log" "path" + "regexp" "strings" "time" @@ -51,6 +52,10 @@ const ( metadataLimit = dropbox.MetadataLimitDefault // max items to fetch at once ) +// A regexp matching path names for files Dropbox ignores +// See https://www.dropbox.com/en/help/145 - Ignored files +var ignoredFiles = regexp.MustCompile(`(?i)(^|/)(desktop\.ini|thumbs\.db|\.ds_store|icon\r|\.dropbox|\.dropbox.attr)$`) + // Register with Fs func init() { fs.Register(&fs.FsInfo{ @@ -542,7 +547,12 @@ func (o *FsObjectDropbox) Open() (in io.ReadCloser, err error) { // // The new object may have been created if an error is returned func (o *FsObjectDropbox) Update(in io.Reader, modTime time.Time, size int64) error { - entry, err := o.dropbox.db.UploadByChunk(ioutil.NopCloser(in), uploadChunkSize, o.remotePath(), true, "") + remote := o.remotePath() + if ignoredFiles.MatchString(remote) { + fs.ErrorLog(o, "File name disallowed - not uploading") + return nil + } + entry, err := o.dropbox.db.UploadByChunk(ioutil.NopCloser(in), uploadChunkSize, remote, true, "") if err != nil { return fmt.Errorf("Upload failed: %s", err) }