Adjust FileExists to differentiate between error and actual file existence

This commit is contained in:
Oliver Sauder
2017-11-21 11:15:51 +01:00
parent e504fdcd54
commit b2bf4f7884
8 changed files with 49 additions and 22 deletions
+3 -3
View File
@@ -259,12 +259,12 @@ func (storage *PublishedStorage) HardLink(src string, dst string) error {
}
// FileExists returns true if path exists
func (storage *PublishedStorage) FileExists(path string) bool {
func (storage *PublishedStorage) FileExists(path string) (bool, error) {
if _, err := os.Lstat(filepath.Join(storage.rootPath, path)); os.IsNotExist(err) {
return false
return false, nil
}
return true
return true, nil
}
// ReadLink returns the symbolic link pointed to by path
+4 -5
View File
@@ -107,13 +107,13 @@ func (s *PublishedStorageSuite) TestFileExists(c *C) {
err := s.storage.MkDir("ppa/dists/squeeze/")
c.Assert(err, IsNil)
exists := s.storage.FileExists("ppa/dists/squeeze/Release")
exists, _ := s.storage.FileExists("ppa/dists/squeeze/Release")
c.Check(exists, Equals, false)
err = s.storage.PutFile("ppa/dists/squeeze/Release", "/dev/null")
c.Assert(err, IsNil)
exists = s.storage.FileExists("ppa/dists/squeeze/Release")
exists, _ = s.storage.FileExists("ppa/dists/squeeze/Release")
c.Check(exists, Equals, true)
}
@@ -127,7 +127,7 @@ func (s *PublishedStorageSuite) TestSymLink(c *C) {
err = s.storage.SymLink("ppa/dists/squeeze/Release", "ppa/dists/squeeze/InRelease")
c.Assert(err, IsNil)
exists := s.storage.FileExists("ppa/dists/squeeze/InRelease")
exists, _ := s.storage.FileExists("ppa/dists/squeeze/InRelease")
c.Check(exists, Equals, true)
}
@@ -141,11 +141,10 @@ func (s *PublishedStorageSuite) TestHardLink(c *C) {
err = s.storage.HardLink("ppa/dists/squeeze/Release", "ppa/dists/squeeze/InRelease")
c.Assert(err, IsNil)
exists := s.storage.FileExists("ppa/dists/squeeze/InRelease")
exists, _ := s.storage.FileExists("ppa/dists/squeeze/InRelease")
c.Check(exists, Equals, true)
}
func (s *PublishedStorageSuite) TestRemoveDirs(c *C) {
err := s.storage.MkDir("ppa/dists/squeeze/")
c.Assert(err, IsNil)