diff --git a/api/mirror.go b/api/mirror.go index 7e0ed6e0..83dca0ee 100644 --- a/api/mirror.go +++ b/api/mirror.go @@ -2,7 +2,10 @@ package api import ( "fmt" + "io/ioutil" + "log" "net/http" + "os" "sort" "strings" "sync" @@ -482,7 +485,16 @@ func apiMirrorsUpdate(c *gin.Context) { var e error // provision download location - task.TempDownPath, e = context.PackagePool().(aptly.LocalPackagePool).GenerateTempPath(task.File.Filename) + if pp, ok := context.PackagePool().(aptly.LocalPackagePool); ok { + task.TempDownPath, e = pp.GenerateTempPath(task.File.Filename) + } else { + var file *os.File + file, e = ioutil.TempFile("", task.File.Filename) + if e == nil { + task.TempDownPath = file.Name() + file.Close() + } + } if e != nil { pushError(e) continue diff --git a/cmd/mirror_update.go b/cmd/mirror_update.go index 111590bb..f2219bcd 100644 --- a/cmd/mirror_update.go +++ b/cmd/mirror_update.go @@ -2,6 +2,8 @@ package cmd import ( "fmt" + "io/ioutil" + "os" "strings" "sync" @@ -161,7 +163,16 @@ func aptlyMirrorUpdate(cmd *commander.Command, args []string) error { var e error // provision download location - task.TempDownPath, e = context.PackagePool().(aptly.LocalPackagePool).GenerateTempPath(task.File.Filename) + if pp, ok := context.PackagePool().(aptly.LocalPackagePool); ok { + task.TempDownPath, e = pp.GenerateTempPath(task.File.Filename) + } else { + var file *os.File + file, e = ioutil.TempFile("", task.File.Filename) + if e == nil { + task.TempDownPath = file.Name() + file.Close() + } + } if e != nil { pushError(e) continue diff --git a/files/public.go b/files/public.go index cab54c97..848f0c23 100644 --- a/files/public.go +++ b/files/public.go @@ -133,26 +133,37 @@ func (storage *PublishedStorage) LinkFromPool(publishedPrefix, publishedRelPath, baseName := filepath.Base(fileName) poolPath := filepath.Join(storage.rootPath, publishedPrefix, publishedRelPath, filepath.Dir(fileName)) + var localSourcePool aptly.LocalPackagePool + if storage.linkMethod != LinkMethodCopy { + pp, ok := sourcePool.(aptly.LocalPackagePool) + if !ok { + return fmt.Errorf("cannot link %s from non-local pool %s", baseName, sourcePool) + } + + localSourcePool = pp + } + err := os.MkdirAll(poolPath, 0777) if err != nil { return err } - var dstStat, srcStat os.FileInfo + var dstStat os.FileInfo dstStat, err = os.Stat(filepath.Join(poolPath, baseName)) if err == nil { // already exists, check source file - srcStat, err = sourcePool.Stat(sourcePath) - if err != nil { - // source file doesn't exist? problem! - return err - } if storage.linkMethod == LinkMethodCopy { + srcSize, err := sourcePool.Size(sourcePath) + if err != nil { + // source file doesn't exist? problem! + return err + } + if storage.verifyMethod == VerificationMethodFileSize { // if source and destination have the same size, no need to copy - if srcStat.Size() == dstStat.Size() { + if srcSize == dstStat.Size() { return nil } } else { @@ -169,6 +180,12 @@ func (storage *PublishedStorage) LinkFromPool(publishedPrefix, publishedRelPath, } } } else { + srcStat, err := localSourcePool.Stat(sourcePath) + if err != nil { + // source file doesn't exist? problem! + return err + } + srcSys := srcStat.Sys().(*syscall.Stat_t) dstSys := dstStat.Sys().(*syscall.Stat_t) @@ -223,9 +240,9 @@ func (storage *PublishedStorage) LinkFromPool(publishedPrefix, publishedRelPath, err = dst.Close() } else if storage.linkMethod == LinkMethodSymLink { - err = sourcePool.(aptly.LocalPackagePool).Symlink(sourcePath, filepath.Join(poolPath, baseName)) + err = localSourcePool.Symlink(sourcePath, filepath.Join(poolPath, baseName)) } else { - err = sourcePool.(aptly.LocalPackagePool).Link(sourcePath, filepath.Join(poolPath, baseName)) + err = localSourcePool.Link(sourcePath, filepath.Join(poolPath, baseName)) } return err