From c70c1964201595f266a3a5b39f1b2a911c9f1ff4 Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Tue, 22 Apr 2014 10:40:17 +0400 Subject: [PATCH] Renaming files in public area. #8 --- aptly/interfaces.go | 2 ++ files/public.go | 5 +++++ files/public_test.go | 15 +++++++++++++++ 3 files changed, 22 insertions(+) diff --git a/aptly/interfaces.go b/aptly/interfaces.go index c98395b6..f23a67f5 100644 --- a/aptly/interfaces.go +++ b/aptly/interfaces.go @@ -38,6 +38,8 @@ type PublishedStorage interface { LinkFromPool(prefix string, component string, poolDirectory string, sourcePool PackagePool, sourcePath string) (string, error) // ChecksumsForFile proxies requests to utils.ChecksumsForFile, joining public path 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 diff --git a/files/public.go b/files/public.go index 58c7e732..72dfaad2 100644 --- a/files/public.go +++ b/files/public.go @@ -81,3 +81,8 @@ func (storage *PublishedStorage) LinkFromPool(prefix string, component string, p func (storage *PublishedStorage) ChecksumsForFile(path string) (utils.ChecksumInfo, error) { 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)) +} diff --git a/files/public_test.go b/files/public_test.go index c1d1f3d0..f310bc40 100644 --- a/files/public_test.go +++ b/files/public_test.go @@ -44,6 +44,21 @@ func (s *PublishedStorageSuite) TestCreateFile(c *C) { 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) { err := s.storage.MkDir("ppa/dists/squeeze/") c.Assert(err, IsNil)