diff --git a/debian/repository.go b/debian/repository.go index ffe03065..e82418fc 100644 --- a/debian/repository.go +++ b/debian/repository.go @@ -59,6 +59,13 @@ func (r *Repository) CreateFile(path string) (*os.File, error) { return os.Create(filepath.Join(r.RootPath, "public", path)) } +// RemoveDirs removes directory structure under public path +func (r *Repository) RemoveDirs(path string) error { + filepath := filepath.Join(r.RootPath, "public", path) + fmt.Printf("Removing %s...\n", filepath) + return os.RemoveAll(filepath) +} + // LinkFromPool links package file from pool to dist's pool location func (r *Repository) LinkFromPool(prefix string, component string, sourcePath string, poolDirectory string) (string, error) { baseName := filepath.Base(sourcePath) diff --git a/debian/repository_test.go b/debian/repository_test.go index 424ba193..9026916a 100644 --- a/debian/repository_test.go +++ b/debian/repository_test.go @@ -52,6 +52,21 @@ func (s *RepositorySuite) TestCreateFile(c *C) { c.Assert(err, IsNil) } +func (s *RepositorySuite) TestRemoveDirs(c *C) { + err := s.repo.MkDir("ppa/dists/squeeze/") + c.Assert(err, IsNil) + + file, err := s.repo.CreateFile("ppa/dists/squeeze/Release") + c.Assert(err, IsNil) + defer file.Close() + + err = s.repo.RemoveDirs("ppa/dists/") + + _, err = os.Stat(filepath.Join(s.repo.RootPath, "public/ppa/dists/squeeze/Release")) + c.Assert(err, NotNil) + c.Assert(os.IsNotExist(err), Equals, true) +} + func (s *RepositorySuite) TestLinkFromPool(c *C) { tests := []struct { prefix string