mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-04-19 19:28:22 +00:00
Implement FileExists in files storage as simple stat to improve performance
This commit is contained in:
@@ -202,7 +202,7 @@ func packageIndexByHash(file *indexFile, ext string, hash string, sum string) er
|
||||
}
|
||||
|
||||
// create symlink
|
||||
err = file.parent.publishedStorage.SymLink(sum, filepath.Join(dst, indexfile))
|
||||
err = file.parent.publishedStorage.SymLink(filepath.Join(dst, sum), filepath.Join(dst, indexfile))
|
||||
if err != nil {
|
||||
return fmt.Errorf("Acquire-By-Hash: error creating symlink %s", filepath.Join(dst, indexfile))
|
||||
}
|
||||
|
||||
@@ -250,7 +250,7 @@ func (storage *PublishedStorage) RenameFile(oldName, newName string) error {
|
||||
|
||||
// SymLink creates a symbolic link, which can be read with ReadLink
|
||||
func (storage *PublishedStorage) SymLink(src string, dst string) error {
|
||||
return os.Symlink(src, filepath.Join(storage.rootPath, dst))
|
||||
return os.Symlink(filepath.Join(storage.rootPath, src), filepath.Join(storage.rootPath, dst))
|
||||
}
|
||||
|
||||
// HardLink creates a hardlink of a file
|
||||
@@ -260,17 +260,11 @@ func (storage *PublishedStorage) HardLink(src string, dst string) error {
|
||||
|
||||
// FileExists returns true if path exists
|
||||
func (storage *PublishedStorage) FileExists(path string) bool {
|
||||
list, err := storage.Filelist(filepath.Dir(path))
|
||||
if err != nil {
|
||||
if _, err := os.Lstat(filepath.Join(storage.rootPath, path)); os.IsNotExist(err) {
|
||||
return false
|
||||
}
|
||||
f := filepath.Base(path)
|
||||
for _, i := range list {
|
||||
if i == f {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// ReadLink returns the symbolic link pointed to by path
|
||||
|
||||
@@ -103,6 +103,49 @@ func (s *PublishedStorageSuite) TestRenameFile(c *C) {
|
||||
c.Assert(err, IsNil)
|
||||
}
|
||||
|
||||
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")
|
||||
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")
|
||||
c.Check(exists, Equals, true)
|
||||
}
|
||||
|
||||
func (s *PublishedStorageSuite) TestSymLink(c *C) {
|
||||
err := s.storage.MkDir("ppa/dists/squeeze/")
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
err = s.storage.PutFile("ppa/dists/squeeze/Release", "/dev/null")
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
err = s.storage.SymLink("ppa/dists/squeeze/Release", "ppa/dists/squeeze/InRelease")
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
exists := s.storage.FileExists("ppa/dists/squeeze/InRelease")
|
||||
c.Check(exists, Equals, true)
|
||||
}
|
||||
|
||||
func (s *PublishedStorageSuite) TestHardLink(c *C) {
|
||||
err := s.storage.MkDir("ppa/dists/squeeze/")
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
err = s.storage.PutFile("ppa/dists/squeeze/Release", "/dev/null")
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
err = s.storage.HardLink("ppa/dists/squeeze/Release", "ppa/dists/squeeze/InRelease")
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user