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