From 74eb698e45c19f6e9be7c98500c01d1b16e2d53d Mon Sep 17 00:00:00 2001 From: rick olson Date: Tue, 12 Sep 2017 08:19:26 -0600 Subject: [PATCH] move helper methods to exclusive file that they're used in --- commands/commands.go | 54 ------------------------------------------- commands/uploader.go | 55 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 54 deletions(-) diff --git a/commands/commands.go b/commands/commands.go index 94473ad5..a96d0cf2 100644 --- a/commands/commands.go +++ b/commands/commands.go @@ -121,60 +121,6 @@ func downloadTransfer(p *lfs.WrappedPointer) (name, path, oid string, size int64 return p.Name, path, p.Oid, p.Size } -func uploadTransfer(p *lfs.WrappedPointer) (*tq.Transfer, error) { - filename := p.Name - oid := p.Oid - - localMediaPath, err := lfs.LocalMediaPath(oid) - if err != nil { - return nil, errors.Wrapf(err, "Error uploading file %s (%s)", filename, oid) - } - - if len(filename) > 0 { - if err = ensureFile(filename, localMediaPath); err != nil && !errors.IsCleanPointerError(err) { - return nil, err - } - } - - return &tq.Transfer{ - Name: filename, - Path: localMediaPath, - Oid: oid, - Size: p.Size, - }, nil -} - -// ensureFile makes sure that the cleanPath exists before pushing it. If it -// does not exist, it attempts to clean it by reading the file at smudgePath. -func ensureFile(smudgePath, cleanPath string) error { - if _, err := os.Stat(cleanPath); err == nil { - return nil - } - - localPath := filepath.Join(config.LocalWorkingDir, smudgePath) - file, err := os.Open(localPath) - if err != nil { - return err - } - - defer file.Close() - - stat, err := file.Stat() - if err != nil { - return err - } - - cleaned, err := lfs.PointerClean(file, file.Name(), stat.Size(), nil) - if cleaned != nil { - cleaned.Teardown() - } - - if err != nil { - return err - } - return nil -} - // Error prints a formatted message to Stderr. It also gets printed to the // panic log if one is created for this command. func Error(format string, args ...interface{}) { diff --git a/commands/uploader.go b/commands/uploader.go index 0a170397..17a0020d 100644 --- a/commands/uploader.go +++ b/commands/uploader.go @@ -4,6 +4,7 @@ import ( "fmt" "net/url" "os" + "path/filepath" "strconv" "strings" "sync" @@ -374,6 +375,60 @@ var ( } ) +func uploadTransfer(p *lfs.WrappedPointer) (*tq.Transfer, error) { + filename := p.Name + oid := p.Oid + + localMediaPath, err := lfs.LocalMediaPath(oid) + if err != nil { + return nil, errors.Wrapf(err, "Error uploading file %s (%s)", filename, oid) + } + + if len(filename) > 0 { + if err = ensureFile(filename, localMediaPath); err != nil && !errors.IsCleanPointerError(err) { + return nil, err + } + } + + return &tq.Transfer{ + Name: filename, + Path: localMediaPath, + Oid: oid, + Size: p.Size, + }, nil +} + +// ensureFile makes sure that the cleanPath exists before pushing it. If it +// does not exist, it attempts to clean it by reading the file at smudgePath. +func ensureFile(smudgePath, cleanPath string) error { + if _, err := os.Stat(cleanPath); err == nil { + return nil + } + + localPath := filepath.Join(config.LocalWorkingDir, smudgePath) + file, err := os.Open(localPath) + if err != nil { + return err + } + + defer file.Close() + + stat, err := file.Stat() + if err != nil { + return err + } + + cleaned, err := lfs.PointerClean(file, file.Name(), stat.Size(), nil) + if cleaned != nil { + cleaned.Teardown() + } + + if err != nil { + return err + } + return nil +} + // getVerifyStateFor returns whether or not lock verification is enabled for the // given "endpoint". If no state has been explicitly set, an "unknown" state // will be returned instead.