mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-06-04 05:10:40 +00:00
New methods for public root: Filelist and Remove. #8
This commit is contained in:
+5
-1
@@ -34,8 +34,12 @@ type PublishedStorage interface {
|
|||||||
CreateFile(path string) (*os.File, error)
|
CreateFile(path string) (*os.File, error)
|
||||||
// RemoveDirs removes directory structure under public path
|
// RemoveDirs removes directory structure under public path
|
||||||
RemoveDirs(path string) error
|
RemoveDirs(path string) error
|
||||||
|
// Remove removes single file under public path
|
||||||
|
Remove(path string) error
|
||||||
// LinkFromPool links package file from pool to dist's pool location
|
// LinkFromPool links package file from pool to dist's pool location
|
||||||
LinkFromPool(prefix string, component string, poolDirectory string, sourcePool PackagePool, sourcePath string) (string, error)
|
LinkFromPool(publishedDirectory string, sourcePool PackagePool, sourcePath string) error
|
||||||
|
// Filelist returns list of files under prefix
|
||||||
|
Filelist(prefix string) ([]string, error)
|
||||||
// ChecksumsForFile proxies requests to utils.ChecksumsForFile, joining public path
|
// ChecksumsForFile proxies requests to utils.ChecksumsForFile, joining public path
|
||||||
ChecksumsForFile(path string) (utils.ChecksumInfo, error)
|
ChecksumsForFile(path string) (utils.ChecksumInfo, error)
|
||||||
// RenameFile renames (moves) file
|
// RenameFile renames (moves) file
|
||||||
|
|||||||
@@ -38,6 +38,13 @@ func (storage *PublishedStorage) CreateFile(path string) (*os.File, error) {
|
|||||||
return os.Create(filepath.Join(storage.rootPath, path))
|
return os.Create(filepath.Join(storage.rootPath, path))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remove removes single file under public path
|
||||||
|
func (storage *PublishedStorage) Remove(path string) error {
|
||||||
|
filepath := filepath.Join(storage.rootPath, path)
|
||||||
|
fmt.Printf("Removing %s...\n", filepath)
|
||||||
|
return os.Remove(filepath)
|
||||||
|
}
|
||||||
|
|
||||||
// RemoveDirs removes directory structure under public path
|
// RemoveDirs removes directory structure under public path
|
||||||
func (storage *PublishedStorage) RemoveDirs(path string) error {
|
func (storage *PublishedStorage) RemoveDirs(path string) error {
|
||||||
filepath := filepath.Join(storage.rootPath, path)
|
filepath := filepath.Join(storage.rootPath, path)
|
||||||
@@ -72,6 +79,24 @@ func (storage *PublishedStorage) LinkFromPool(publishedDirectory string, sourceP
|
|||||||
return os.Link(sourcePath, filepath.Join(poolPath, baseName))
|
return os.Link(sourcePath, filepath.Join(poolPath, baseName))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Filelist returns list of files under prefix
|
||||||
|
func (storage *PublishedStorage) Filelist(prefix string) ([]string, error) {
|
||||||
|
root := filepath.Join(storage.rootPath, prefix)
|
||||||
|
result := []string{}
|
||||||
|
|
||||||
|
err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if !info.IsDir() {
|
||||||
|
result = append(result, path[len(root)+1:])
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
return result, err
|
||||||
|
}
|
||||||
|
|
||||||
// ChecksumsForFile proxies requests to utils.ChecksumsForFile, joining public path
|
// ChecksumsForFile proxies requests to utils.ChecksumsForFile, joining public path
|
||||||
func (storage *PublishedStorage) ChecksumsForFile(path string) (utils.ChecksumInfo, error) {
|
func (storage *PublishedStorage) ChecksumsForFile(path string) (utils.ChecksumInfo, error) {
|
||||||
return utils.ChecksumsForFile(filepath.Join(storage.rootPath, path))
|
return utils.ChecksumsForFile(filepath.Join(storage.rootPath, path))
|
||||||
|
|||||||
@@ -44,6 +44,23 @@ func (s *PublishedStorageSuite) TestCreateFile(c *C) {
|
|||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *PublishedStorageSuite) TestFilelist(c *C) {
|
||||||
|
err := s.storage.MkDir("ppa/pool/main/a/ab/")
|
||||||
|
c.Assert(err, IsNil)
|
||||||
|
|
||||||
|
file, err := s.storage.CreateFile("ppa/pool/main/a/ab/a.deb")
|
||||||
|
c.Assert(err, IsNil)
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
|
file2, err := s.storage.CreateFile("ppa/pool/main/a/ab/b.deb")
|
||||||
|
c.Assert(err, IsNil)
|
||||||
|
defer file2.Close()
|
||||||
|
|
||||||
|
list, err := s.storage.Filelist("ppa/pool/main/")
|
||||||
|
c.Check(err, IsNil)
|
||||||
|
c.Check(list, DeepEquals, []string{"a/ab/a.deb", "a/ab/b.deb"})
|
||||||
|
}
|
||||||
|
|
||||||
func (s *PublishedStorageSuite) TestRenameFile(c *C) {
|
func (s *PublishedStorageSuite) TestRenameFile(c *C) {
|
||||||
err := s.storage.MkDir("ppa/dists/squeeze/")
|
err := s.storage.MkDir("ppa/dists/squeeze/")
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
@@ -74,6 +91,21 @@ func (s *PublishedStorageSuite) TestRemoveDirs(c *C) {
|
|||||||
c.Assert(os.IsNotExist(err), Equals, true)
|
c.Assert(os.IsNotExist(err), Equals, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *PublishedStorageSuite) TestRemove(c *C) {
|
||||||
|
err := s.storage.MkDir("ppa/dists/squeeze/")
|
||||||
|
c.Assert(err, IsNil)
|
||||||
|
|
||||||
|
file, err := s.storage.CreateFile("ppa/dists/squeeze/Release")
|
||||||
|
c.Assert(err, IsNil)
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
|
err = s.storage.Remove("ppa/dists/squeeze/Release")
|
||||||
|
|
||||||
|
_, err = os.Stat(filepath.Join(s.storage.rootPath, "ppa/dists/squeeze/Release"))
|
||||||
|
c.Assert(err, NotNil)
|
||||||
|
c.Assert(os.IsNotExist(err), Equals, true)
|
||||||
|
}
|
||||||
|
|
||||||
func (s *PublishedStorageSuite) TestLinkFromPool(c *C) {
|
func (s *PublishedStorageSuite) TestLinkFromPool(c *C) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
prefix string
|
prefix string
|
||||||
|
|||||||
Reference in New Issue
Block a user