mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-04-20 19:38:39 +00:00
Move Stat() into LocalPackagePool
The contents of `os.Stat` are rather fitted towards local package pools, but the method is in the generic PackagePool interface. This moves it to LocalPackagePool, and the use case of simply finding a file's size is delegated to a new, more generic PackagePool.Size() method. Signed-off-by: Ryan Gonzalez <ryan.gonzalez@collabora.com>
This commit is contained in:
committed by
André Roth
parent
8e37813129
commit
1ebd37f9ad
@@ -379,6 +379,15 @@ func (pool *PackagePool) Import(srcPath, basename string, checksums *utils.Check
|
||||
return poolPath, err
|
||||
}
|
||||
|
||||
func (pool *PackagePool) Size(path string) (size int64, err error) {
|
||||
stat, err := pool.Stat(path)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return stat.Size(), nil
|
||||
}
|
||||
|
||||
// Open returns io.ReadCloser to access the file
|
||||
func (pool *PackagePool) Open(path string) (aptly.ReadSeekerCloser, error) {
|
||||
return os.Open(filepath.Join(pool.rootPath, path))
|
||||
|
||||
@@ -306,6 +306,18 @@ func (s *PackagePoolSuite) TestImportOverwrite(c *C) {
|
||||
c.Check(err, ErrorMatches, "unable to import into pool.*")
|
||||
}
|
||||
|
||||
func (s *PackagePoolSuite) TestSize(c *C) {
|
||||
path, err := s.pool.Import(s.debFile, filepath.Base(s.debFile), &s.checksum, false, s.cs)
|
||||
c.Check(err, IsNil)
|
||||
|
||||
size, err := s.pool.Size(path)
|
||||
c.Assert(err, IsNil)
|
||||
c.Check(size, Equals, int64(2738))
|
||||
|
||||
_, err = s.pool.Size("do/es/ntexist")
|
||||
c.Assert(os.IsNotExist(err), Equals, true)
|
||||
}
|
||||
|
||||
func (s *PackagePoolSuite) TestStat(c *C) {
|
||||
path, err := s.pool.Import(s.debFile, filepath.Base(s.debFile), &s.checksum, false, s.cs)
|
||||
c.Check(err, IsNil)
|
||||
|
||||
Reference in New Issue
Block a user