Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Michal-Leszczynski committed Nov 21, 2023
1 parent 6a717bf commit 4aaf89b
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 35 deletions.
50 changes: 28 additions & 22 deletions backend/b2/b2.go
Original file line number Diff line number Diff line change
Expand Up @@ -635,12 +635,12 @@ var errEndList = errors.New("end list")
//
// (bucket, directory) is the starting directory
//
// If prefix is set then it is removed from all file names
// # If prefix is set then it is removed from all file names
//
// If addBucket is set then it adds the bucket to the start of the
// remotes generated
//
// If recurse is set the function will recursively list
// # If recurse is set the function will recursively list
//
// If limit is > 0 then it limits to that many files (must be less
// than 1000)
Expand Down Expand Up @@ -987,7 +987,7 @@ func (f *Fs) clearBucketID(bucket string) {

// Put the object into the bucket
//
// Copy the reader in to the new object which is returned
// # Copy the reader in to the new object which is returned
//
// The new object may have been created if an error is returned
func (f *Fs) Put(ctx context.Context, in io.Reader, src fs.ObjectInfo, options ...fs.OpenOption) (fs.Object, error) {
Expand Down Expand Up @@ -1189,6 +1189,7 @@ func (f *Fs) purge(ctx context.Context, dir string, oldOnly bool) error {
tr := accounting.Stats(ctx).NewCheckingTransfer(oi)
err = f.deleteByID(ctx, object.ID, object.Name)
checkErr(err)
tr.IdenticalCheck(9997)
tr.Done(ctx, err)
}
}()
Expand Down Expand Up @@ -1217,6 +1218,7 @@ func (f *Fs) purge(ctx context.Context, dir string, oldOnly bool) error {
toBeDeleted <- object
}
last = remote
tr.IdenticalCheck(9996)
tr.Done(ctx, nil)
}
return nil
Expand Down Expand Up @@ -1299,9 +1301,9 @@ func (f *Fs) copy(ctx context.Context, dstObj *Object, srcObj *Object, newInfo *

// Copy src to this remote using server-side copy operations.
//
// This is stored with the remote path given
// # This is stored with the remote path given
//
// It returns the destination Object and a possible error
// # It returns the destination Object and a possible error
//
// Will only be called if src.Fs().Name() == f.Name()
//
Expand Down Expand Up @@ -1443,7 +1445,7 @@ func (o *Object) Size() int64 {

// Clean the SHA1
//
// Make sure it is lower case
// # Make sure it is lower case
//
// Remove unverified prefix - see https://www.backblaze.com/b2/docs/uploading.html
// Some tools (e.g. Cyberduck) use this
Expand All @@ -1459,10 +1461,11 @@ func cleanSHA1(sha1 string) (out string) {
// decodeMetaDataRaw sets the metadata from the data passed in
//
// Sets
// o.id
// o.modTime
// o.size
// o.sha1
//
// o.id
// o.modTime
// o.size
// o.sha1
func (o *Object) decodeMetaDataRaw(ID, SHA1 string, Size int64, UploadTimestamp api.Timestamp, Info map[string]string, mimeType string) (err error) {
o.id = ID
o.sha1 = SHA1
Expand All @@ -1481,21 +1484,23 @@ func (o *Object) decodeMetaDataRaw(ID, SHA1 string, Size int64, UploadTimestamp
// decodeMetaData sets the metadata in the object from an api.File
//
// Sets
// o.id
// o.modTime
// o.size
// o.sha1
//
// o.id
// o.modTime
// o.size
// o.sha1
func (o *Object) decodeMetaData(info *api.File) (err error) {
return o.decodeMetaDataRaw(info.ID, info.SHA1, info.Size, info.UploadTimestamp, info.Info, info.ContentType)
}

// decodeMetaDataFileInfo sets the metadata in the object from an api.FileInfo
//
// Sets
// o.id
// o.modTime
// o.size
// o.sha1
//
// o.id
// o.modTime
// o.size
// o.sha1
func (o *Object) decodeMetaDataFileInfo(info *api.FileInfo) (err error) {
return o.decodeMetaDataRaw(info.ID, info.SHA1, info.Size, info.UploadTimestamp, info.Info, info.ContentType)
}
Expand Down Expand Up @@ -1553,10 +1558,11 @@ func (o *Object) getMetaData(ctx context.Context) (info *api.File, err error) {
// readMetaData gets the metadata if it hasn't already been fetched
//
// Sets
// o.id
// o.modTime
// o.size
// o.sha1
//
// o.id
// o.modTime
// o.size
// o.sha1
func (o *Object) readMetaData(ctx context.Context) (err error) {
if o.id != "" {
return nil
Expand Down
4 changes: 1 addition & 3 deletions fs/operations/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,7 @@ func (c *checkMarch) checkIdentical(ctx context.Context, dst, src fs.Object) (di
ci := fs.GetConfig(ctx)
tr := accounting.Stats(ctx).NewCheckingTransfer(src)
defer func() {
if !differ {
tr.IdenticalCheck(9998)
}
tr.IdenticalCheck(9998)
tr.Done(ctx, err)
}()
if sizeDiffers(ctx, src, dst) {
Expand Down
13 changes: 9 additions & 4 deletions fs/operations/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import (
// CheckHashes checks the two files to see if they have common
// known hash types and compares them
//
// Returns
// # Returns
//
// equal - which is equality of the hashes
//
Expand Down Expand Up @@ -568,6 +568,7 @@ func Move(ctx context.Context, fdst fs.Fs, dst fs.Object, remote string, src fs.
if err == nil {
accounting.Stats(ctx).Renames(1)
}
tr.IdenticalCheck(9995)
tr.Done(ctx, err)
}()
newDst = dst
Expand Down Expand Up @@ -649,6 +650,7 @@ func DeleteFileWithBackupDir(ctx context.Context, dst fs.Object, backupDir fs.Fs
ci := fs.GetConfig(ctx)
tr := accounting.Stats(ctx).NewCheckingTransfer(dst)
defer func() {
tr.IdenticalCheck(9994)
tr.Done(ctx, err)
}()
numDeletes := accounting.Stats(ctx).Deletes(1)
Expand Down Expand Up @@ -821,7 +823,7 @@ var SyncPrintf = func(format string, a ...interface{}) {

// Synchronized fmt.Fprintf
//
// Ignores errors from Fprintf
// # Ignores errors from Fprintf
//
// Updated to print to terminal if no writer is defined
// This special behavior is used to allow easier replacement of the print to terminal code by progress
Expand All @@ -837,7 +839,7 @@ func syncFprintf(w io.Writer, format string, a ...interface{}) {

// List the Fs to the supplied writer
//
// Shows size and path - obeys includes and excludes
// # Shows size and path - obeys includes and excludes
//
// Lists in parallel which may get them out of order
func List(ctx context.Context, f fs.Fs, w io.Writer) error {
Expand All @@ -848,13 +850,14 @@ func List(ctx context.Context, f fs.Fs, w io.Writer) error {

// ListLong lists the Fs to the supplied writer
//
// Shows size, mod time and path - obeys includes and excludes
// # Shows size, mod time and path - obeys includes and excludes
//
// Lists in parallel which may get them out of order
func ListLong(ctx context.Context, f fs.Fs, w io.Writer) error {
return ListFn(ctx, f, func(o fs.Object) {
tr := accounting.Stats(ctx).NewCheckingTransfer(o)
defer func() {
tr.IdenticalCheck(9993)
tr.Done(ctx, nil)
}()
modTime := o.ModTime(ctx)
Expand Down Expand Up @@ -914,6 +917,7 @@ func hashSum(ctx context.Context, ht hash.Type, downloadFlag bool, o fs.Object)
} else {
tr := accounting.Stats(ctx).NewCheckingTransfer(o)
defer func() {
tr.IdenticalCheck(9992)
tr.Done(ctx, err)
}()

Expand Down Expand Up @@ -1763,6 +1767,7 @@ func moveOrCopyFile(ctx context.Context, fdst fs.Fs, fsrc fs.Fs, dstFileName str
if !cp {
err = DeleteFile(ctx, srcObj)
}
tr.IdenticalCheck(9991)
tr.Done(ctx, err)
}
return err
Expand Down
9 changes: 3 additions & 6 deletions fs/sync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,13 +318,11 @@ func (s *syncCopyMove) pairChecker(in *pipe, out *pipe, fraction int, wg *sync.W
var err error
tr := accounting.Stats(s.ctx).NewCheckingTransfer(src)
// Check to see if can store this
haha := false
if src.Storable() {
NoNeedTransfer, err := operations.CompareOrCopyDest(s.ctx, s.fdst, pair.Dst, pair.Src, s.compareCopyDest, s.backupDir)
if err != nil {
s.processError(err)
}
haha = NoNeedTransfer
if !NoNeedTransfer && operations.NeedTransfer(s.ctx, pair.Dst, pair.Src) {
// If files are treated as immutable, fail if destination exists and does not match
if s.ci.Immutable && pair.Dst != nil {
Expand Down Expand Up @@ -364,9 +362,8 @@ func (s *syncCopyMove) pairChecker(in *pipe, out *pipe, fraction int, wg *sync.W
}
}
}
if haha {
tr.IdenticalCheck(9999)
}

tr.IdenticalCheck(9999)
tr.Done(s.ctx, err)
}
}
Expand Down Expand Up @@ -788,7 +785,7 @@ func (s *syncCopyMove) makeRenameMap() {
if hash != "" {
s.pushRenameMap(hash, obj)
}

tr.IdenticalCheck(8999)
tr.Done(s.ctx, nil)
}
}
Expand Down

0 comments on commit 4aaf89b

Please sign in to comment.