mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-06-05 05:20:34 +00:00
Merge pull request #705 from apachelogger/prevent-root-remove
prevent removal of a PublishedStorage's root dir
This commit is contained in:
@@ -97,12 +97,18 @@ func (storage *PublishedStorage) PutFile(path string, sourceFilename string) err
|
||||
|
||||
// Remove removes single file under public path
|
||||
func (storage *PublishedStorage) Remove(path string) error {
|
||||
if len(path) <= 0 {
|
||||
panic("trying to remove empty path")
|
||||
}
|
||||
filepath := filepath.Join(storage.rootPath, path)
|
||||
return os.Remove(filepath)
|
||||
}
|
||||
|
||||
// RemoveDirs removes directory structure under public path
|
||||
func (storage *PublishedStorage) RemoveDirs(path string, progress aptly.Progress) error {
|
||||
if len(path) <= 0 {
|
||||
panic("trying to remove the root directory")
|
||||
}
|
||||
filepath := filepath.Join(storage.rootPath, path)
|
||||
if progress != nil {
|
||||
progress.Printf("Removing %s...\n", filepath)
|
||||
|
||||
@@ -320,3 +320,19 @@ func (s *PublishedStorageSuite) TestLinkFromPool(c *C) {
|
||||
err = s.storageCopySize.LinkFromPool(filepath.Join("", "pool", "main", "m/mars-invaders"), "mars-invaders_1.03.deb", pool, srcPoolPath, sourceChecksum, false)
|
||||
c.Check(err, IsNil)
|
||||
}
|
||||
|
||||
func (s *PublishedStorageSuite) TestRootRemove(c *C) {
|
||||
// Prevent deletion of the root directory by passing empty subpaths.
|
||||
|
||||
pwd := c.MkDir()
|
||||
|
||||
// Symlink
|
||||
linkedDir := filepath.Join(pwd, "linkedDir")
|
||||
os.Symlink(s.root, linkedDir)
|
||||
linkStorage := NewPublishedStorage(linkedDir, "", "")
|
||||
c.Assert(func() { linkStorage.Remove("") }, PanicMatches, "trying to remove empty path")
|
||||
|
||||
// Actual dir
|
||||
dirStorage := NewPublishedStorage(pwd, "", "")
|
||||
c.Assert(func() { dirStorage.RemoveDirs("", nil) }, PanicMatches, "trying to remove the root directory")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user