Renaming files in public area. #8

This commit is contained in:
Andrey Smirnov
2014-04-22 10:40:17 +04:00
parent e81f86f942
commit c70c196420
3 changed files with 22 additions and 0 deletions
+2
View File
@@ -38,6 +38,8 @@ type PublishedStorage interface {
LinkFromPool(prefix string, component string, poolDirectory string, sourcePool PackagePool, sourcePath string) (string, error) LinkFromPool(prefix string, component string, poolDirectory string, sourcePool PackagePool, sourcePath 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(oldName, newName string) error
} }
// Progress is a progress displaying entity, it allows progress bars & simple prints // Progress is a progress displaying entity, it allows progress bars & simple prints
+5
View File
@@ -81,3 +81,8 @@ func (storage *PublishedStorage) LinkFromPool(prefix string, component string, p
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))
} }
// RenameFile renames (moves) file
func (storage *PublishedStorage) RenameFile(oldName, newName string) error {
return os.Rename(filepath.Join(storage.rootPath, oldName), filepath.Join(storage.rootPath, newName))
}
+15
View File
@@ -44,6 +44,21 @@ func (s *PublishedStorageSuite) TestCreateFile(c *C) {
c.Assert(err, IsNil) c.Assert(err, IsNil)
} }
func (s *PublishedStorageSuite) TestRenameFile(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.RenameFile("ppa/dists/squeeze/Release", "ppa/dists/squeeze/InRelease")
c.Check(err, IsNil)
_, err = os.Stat(filepath.Join(s.storage.rootPath, "ppa/dists/squeeze/InRelease"))
c.Assert(err, IsNil)
}
func (s *PublishedStorageSuite) TestRemoveDirs(c *C) { func (s *PublishedStorageSuite) TestRemoveDirs(c *C) {
err := s.storage.MkDir("ppa/dists/squeeze/") err := s.storage.MkDir("ppa/dists/squeeze/")
c.Assert(err, IsNil) c.Assert(err, IsNil)