From 5d6593de4ffc1c492372749565c63209963e1619 Mon Sep 17 00:00:00 2001 From: Michal Matczuk Date: Wed, 21 Aug 2019 12:01:39 +0200 Subject: [PATCH] * rc/jobs: Add SetInitialJobID function that allows for setting the jobID --- fs/rc/jobs/job.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/fs/rc/jobs/job.go b/fs/rc/jobs/job.go index b2c18da5b..186127d0f 100644 --- a/fs/rc/jobs/job.go +++ b/fs/rc/jobs/job.go @@ -10,12 +10,10 @@ import ( "sync/atomic" "time" - "github.com/rclone/rclone/fs/rc" - - "github.com/rclone/rclone/fs/accounting" - "github.com/pkg/errors" "github.com/rclone/rclone/fs" + "github.com/rclone/rclone/fs/accounting" + "github.com/rclone/rclone/fs/rc" ) // Job describes a asynchronous task started via the rc package @@ -59,6 +57,13 @@ func SetOpt(opt *rc.Options) { running.opt = opt } +// SetInitialJobID allows for setting jobID before starting any jobs. +func SetInitialJobID(id int64) { + if !atomic.CompareAndSwapInt64(&jobID, 0, id) { + panic("Setting jobID is only possible before starting any jobs") + } +} + // kickExpire makes sure Expire is running func (jobs *Jobs) kickExpire() { jobs.mu.Lock()