lfs: remove LocalMediaPath()

This commit is contained in:
rick olson 2017-10-25 11:31:15 -06:00
parent a30a7bd47e
commit 739128a3fd
14 changed files with 40 additions and 24 deletions

@ -66,7 +66,7 @@ func clean(gf *lfs.GitFilter, to io.Writer, from io.Reader, fileName string, fil
}
tmpfile := cleaned.Filename
mediafile, err := lfs.LocalMediaPath(cleaned.Oid)
mediafile, err := gf.ObjectPath(cleaned.Oid)
if err != nil {
Panic(err, "Unable to get local media path.")
}

@ -275,7 +275,7 @@ func pruneDeleteFiles(prunableObjects []string) {
var deletedFiles int
for i, oid := range prunableObjects {
spinner.Print(OutputWriter, fmt.Sprintf("Deleting object %d/%d", i, len(prunableObjects)))
mediaFile, err := lfs.LocalMediaPath(oid)
mediaFile, err := cfg.Filesystem().ObjectPath(oid)
if err != nil {
problems.WriteString(fmt.Sprintf("Unable to find media path for %v: %v\n", oid, err))
continue

@ -46,7 +46,7 @@ func uploadsBetweenRefAndRemote(ctx *uploadContext, refnames []string) {
func uploadsWithObjectIDs(ctx *uploadContext, oids []string) {
for _, oid := range oids {
mp, err := lfs.LocalMediaPath(oid)
mp, err := ctx.gitfilter.ObjectPath(oid)
if err != nil {
ExitWithError(errors.Wrap(err, "Unable to find local media path:"))
}

@ -52,7 +52,7 @@ func delayedSmudge(gf *lfs.GitFilter, s *git.FilterProcessScanner, to io.Writer,
lfs.LinkOrCopyFromReference(cfg, ptr.Oid, ptr.Size)
path, err := lfs.LocalMediaPath(ptr.Oid)
path, err := cfg.Filesystem().ObjectPath(ptr.Oid)
if err != nil {
return 0, false, nil, err
}

@ -131,8 +131,7 @@ func buildFilepathFilter(config *config.Configuration, includeArg, excludeArg *s
}
func downloadTransfer(p *lfs.WrappedPointer) (name, path, oid string, size int64) {
path, _ = lfs.LocalMediaPath(p.Oid)
path, _ = cfg.Filesystem().ObjectPath(p.Oid)
return p.Name, path, p.Oid, p.Size
}

@ -387,7 +387,7 @@ func (c *uploadContext) uploadTransfer(p *lfs.WrappedPointer) (*tq.Transfer, err
filename := p.Name
oid := p.Oid
localMediaPath, err := lfs.LocalMediaPath(oid)
localMediaPath, err := c.gitfilter.ObjectPath(oid)
if err != nil {
return nil, errors.Wrapf(err, "Error uploading file %s (%s)", filename, oid)
}

@ -33,7 +33,7 @@ func (f *Filesystem) cleanupTmp() error {
return
}
fi, err := os.Stat(f.ObjectPath(oid))
fi, err := os.Stat(f.ObjectPathname(oid))
if err == nil && !fi.IsDir() {
tracerx.Printf("Removing existing tmp object file: %s", path)
os.RemoveAll(path)

@ -1,6 +1,7 @@
package fs
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
@ -47,10 +48,18 @@ func (f *Filesystem) EachObject(fn func(Object) error) error {
}
func (f *Filesystem) ObjectExists(oid string, size int64) bool {
return tools.FileExistsOfSize(f.ObjectPath(oid), size)
return tools.FileExistsOfSize(f.ObjectPathname(oid), size)
}
func (f *Filesystem) ObjectPath(oid string) string {
func (f *Filesystem) ObjectPath(oid string) (string, error) {
dir := f.localObjectDir(oid)
if err := os.MkdirAll(dir, 0755); err != nil {
return "", fmt.Errorf("Error trying to create local storage directory in %q: %s", dir, err)
}
return filepath.Join(dir, oid), nil
}
func (f *Filesystem) ObjectPathname(oid string) string {
return filepath.Join(f.localObjectDir(oid), oid)
}

@ -2,14 +2,20 @@ package lfs
import (
"github.com/git-lfs/git-lfs/config"
"github.com/git-lfs/git-lfs/fs"
)
// GitFilter provides clean and smudge capabilities
type GitFilter struct {
cfg *config.Configuration
fs *fs.Filesystem
}
// NewGitFilter initializes a new *GitFilter
func NewGitFilter(cfg *config.Configuration) *GitFilter {
return &GitFilter{cfg: cfg}
return &GitFilter{cfg: cfg, fs: cfg.Filesystem()}
}
func (f *GitFilter) ObjectPath(oid string) (string, error) {
return f.fs.ObjectPath(oid)
}

@ -37,7 +37,7 @@ func (f *GitFilter) SmudgeToFile(filename string, ptr *Pointer, download bool, m
}
func (f *GitFilter) Smudge(writer io.Writer, ptr *Pointer, workingfile string, download bool, manifest *tq.Manifest, cb progress.CopyCallback) (int64, error) {
mediafile, err := LocalMediaPath(ptr.Oid)
mediafile, err := f.ObjectPath(ptr.Oid)
if err != nil {
return 0, err
}

@ -16,10 +16,6 @@ import (
"github.com/rubyist/tracerx"
)
func LocalMediaPath(oid string) (string, error) {
return localstorage.Objects().BuildObjectPath(oid)
}
func LocalMediaPathReadOnly(oid string) string {
return localstorage.Objects().ObjectPath(oid)
}
@ -108,7 +104,7 @@ func LinkOrCopyFromReference(cfg *config.Configuration, oid string, size int64)
return nil
}
altMediafile := cfg.Filesystem().ObjectReferencePath(oid)
mediafile, err := LocalMediaPath(oid)
mediafile, err := cfg.Filesystem().ObjectPath(oid)
if err != nil {
return err
}

@ -21,7 +21,7 @@ func TestAllCurrentObjectsNone(t *testing.T) {
}()
empty := true
testCfg.EachLFSObject(func(obj fs.Object) error {
repo.EachLFSObject(func(obj fs.Object) error {
empty = false
t.Logf("Found: %+v", obj)
return nil
@ -60,7 +60,7 @@ func TestAllCurrentObjectsSome(t *testing.T) {
}
actual := make([]*lfs.Pointer, 0)
testCfg.EachLFSObject(func(obj fs.Object) error {
repo.EachLFSObject(func(obj fs.Object) error {
actual = append(actual, lfs.NewPointer(obj.Oid, obj.Size, nil))
return nil
})

@ -12,7 +12,6 @@ import (
"github.com/git-lfs/git-lfs/config"
"github.com/git-lfs/git-lfs/errors"
"github.com/git-lfs/git-lfs/lfs"
"github.com/git-lfs/git-lfs/lfsapi"
"github.com/git-lfs/git-lfs/progress"
"github.com/git-lfs/git-lfs/test"
@ -195,7 +194,7 @@ func buildTestData(cfg *config.Configuration, manifest *tq.Manifest) (oidsExist,
for _, f := range outputs[0].Files {
oidsExist = append(oidsExist, TestObject{Oid: f.Oid, Size: f.Size})
t, err := uploadTransfer(f.Oid, "Test file")
t, err := uploadTransfer(cfg, f.Oid, "Test file")
if err != nil {
return nil, nil, err
}
@ -316,8 +315,8 @@ func interleaveTestData(slice1, slice2 []TestObject) []TestObject {
return ret
}
func uploadTransfer(oid, filename string) (*tq.Transfer, error) {
localMediaPath, err := lfs.LocalMediaPath(oid)
func uploadTransfer(cfg *config.Configuration, oid, filename string) (*tq.Transfer, error) {
localMediaPath, err := cfg.Filesystem().ObjectPath(oid)
if err != nil {
return nil, errors.Wrapf(err, "Error uploading file %s (%s)", filename, oid)
}

@ -22,6 +22,7 @@ import (
"github.com/git-lfs/git-lfs/config"
"github.com/git-lfs/git-lfs/errors"
"github.com/git-lfs/git-lfs/fs"
"github.com/git-lfs/git-lfs/git"
"github.com/git-lfs/git-lfs/lfs"
"github.com/git-lfs/git-lfs/localstorage"
@ -72,6 +73,7 @@ type Repo struct {
callback RepoCallback
cfg *config.Configuration
gitfilter *lfs.GitFilter
fs *fs.Filesystem
}
// Change to repo dir but save current dir
@ -101,6 +103,10 @@ func (r *Repo) Popd() {
}
}
func (r *Repo) EachLFSObject(fn func(fs.Object) error) error {
return r.fs.EachObject(fn)
}
func (r *Repo) Cleanup() {
// pop out if necessary
r.Popd()
@ -167,6 +173,7 @@ func NewCustomRepo(callback RepoCallback, settings *RepoCreateSettings) *Repo {
default:
ret.GitDir = filepath.Join(ret.Path, ".git")
}
ret.fs = fs.New(ret.GitDir, ret.Path, "")
args = append(args, path)
cmd := exec.Command("git", args...)
err = cmd.Run()
@ -240,7 +247,7 @@ func (infile *FileInput) writeLFSPointer(repo *Repo, inputData io.Reader) (*lfs.
// this only created the temp file, move to final location
tmpfile := cleaned.Filename
storageOnce.Do(func() { localstorage.ResolveDirs(repo.cfg) })
mediafile, err := lfs.LocalMediaPath(cleaned.Oid)
mediafile, err := repo.fs.ObjectPath(cleaned.Oid)
if err != nil {
return nil, errors.Wrap(err, "local media path")
}