Removing files from package pool.

This commit is contained in:
Andrey Smirnov
2014-02-12 15:19:04 +04:00
parent 130efaa350
commit 62ea87dc6c
2 changed files with 35 additions and 0 deletions

13
debian/repository.go vendored
View File

@@ -151,3 +151,16 @@ func (r *Repository) PoolFilepathList(progress *utils.Progress) ([]string, error
return result, nil
}
// PoolRemove deletes file in package pool
func (r *Repository) PoolRemove(path string) (size int64, err error) {
path = filepath.Join(r.RootPath, "pool", path)
info, err := os.Stat(path)
if err != nil {
return 0, err
}
err = os.Remove(path)
return info.Size(), err
}

View File

@@ -160,3 +160,25 @@ func (s *RepositorySuite) TestPoolFilepathList(c *C) {
c.Check(err, IsNil)
c.Check(list, DeepEquals, []string{"ae/0c/1.deb", "ae/0c/2.deb", "bd/0a/3.deb", "bd/0b/4.deb"})
}
func (s *RepositorySuite) TestPoolRemove(c *C) {
os.MkdirAll(filepath.Join(s.repo.RootPath, "pool", "bd", "0b"), 0755)
os.MkdirAll(filepath.Join(s.repo.RootPath, "pool", "bd", "0a"), 0755)
os.MkdirAll(filepath.Join(s.repo.RootPath, "pool", "ae", "0c"), 0755)
ioutil.WriteFile(filepath.Join(s.repo.RootPath, "pool", "ae", "0c", "1.deb"), []byte("1"), 0644)
ioutil.WriteFile(filepath.Join(s.repo.RootPath, "pool", "ae", "0c", "2.deb"), []byte("22"), 0644)
ioutil.WriteFile(filepath.Join(s.repo.RootPath, "pool", "bd", "0a", "3.deb"), []byte("333"), 0644)
ioutil.WriteFile(filepath.Join(s.repo.RootPath, "pool", "bd", "0b", "4.deb"), []byte("4444"), 0644)
size, err := s.repo.PoolRemove("ae/0c/2.deb")
c.Check(err, IsNil)
c.Check(size, Equals, int64(2))
_, err = s.repo.PoolRemove("ae/0c/2.deb")
c.Check(err, ErrorMatches, ".*no such file or directory")
list, err := s.repo.PoolFilepathList(nil)
c.Check(err, IsNil)
c.Check(list, DeepEquals, []string{"ae/0c/1.deb", "bd/0a/3.deb", "bd/0b/4.deb"})
}