From 887834da915b7b18e2525fe142c874cf12a72646 Mon Sep 17 00:00:00 2001 From: Garry McNulty Date: Sun, 2 Dec 2018 18:05:32 +0000 Subject: [PATCH] b2: cleanup unfinished large files The `cleanup` command will delete unfinished large file uploads that were started more than a day ago (to avoid deleting uploads that are potentially still in progress). Fixes #2617 --- backend/b2/b2.go | 9 +++++++++ docs/content/b2.md | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/backend/b2/b2.go b/backend/b2/b2.go index 77c2c5277..048f6b804 100644 --- a/backend/b2/b2.go +++ b/backend/b2/b2.go @@ -980,6 +980,12 @@ func (f *Fs) purge(oldOnly bool) error { errReturn = err } } + var isUnfinishedUploadStale = func(timestamp api.Timestamp) bool { + if time.Since(time.Time(timestamp)).Hours() > 24 { + return true + } + return false + } // Delete Config.Transfers in parallel toBeDeleted := make(chan *api.File, fs.Config.Transfers) @@ -1003,6 +1009,9 @@ func (f *Fs) purge(oldOnly bool) error { if object.Action == "hide" { fs.Debugf(remote, "Deleting current version (id %q) as it is a hide marker", object.ID) toBeDeleted <- object + } else if object.Action == "start" && isUnfinishedUploadStale(object.UploadTimestamp) { + fs.Debugf(remote, "Deleting current version (id %q) as it is a start marker (upload started at %s)", object.ID, time.Time(object.UploadTimestamp).Local()) + toBeDeleted <- object } else { fs.Debugf(remote, "Not deleting current version (id %q) %q", object.ID, object.Action) } diff --git a/docs/content/b2.md b/docs/content/b2.md index a7fecae25..25be69bab 100644 --- a/docs/content/b2.md +++ b/docs/content/b2.md @@ -181,8 +181,8 @@ versions of files, leaving the current ones intact. You can also supply a path and only old versions under that path will be deleted, eg `rclone cleanup remote:bucket/path/to/stuff`. -Note that `cleanup` does not remove partially uploaded files -from the bucket. +Note that `cleanup` will remove partially uploaded files from the bucket +if they are more than a day old. When you `purge` a bucket, the current and the old versions will be deleted then the bucket will be deleted.