1// Package aptly provides common infrastructure that doesn't depend directly on 2// Debian or CentOS 3package aptly 4 5import ( 6 "context" 7 "io" 8 "os" 9 10 "github.com/aptly-dev/aptly/utils" 11) 12 13// ReadSeekerCloser = ReadSeeker + Closer 14type ReadSeekerCloser interface { 15 io.ReadSeeker 16 io.Closer 17} 18 19// PackagePool is asbtraction of package pool storage. 20// 21// PackagePool stores all the package files, deduplicating them. 22type PackagePool interface { 23 // Verify checks whether file exists in the pool and fills back checksum info 24 // 25 // if poolPath is empty, poolPath is generated automatically based on checksum info (if available) 26 // in any case, if function returns true, it also fills back checksums with complete information about the file in the pool 27 Verify(poolPath, basename string, checksums *utils.ChecksumInfo, checksumStorage ChecksumStorage) (string, bool, error) 28 // Import copies file into package pool 29 // 30 // - srcPath is full path to source file as it is now 31 // - basename is desired human-readable name (canonical filename) 32 // - checksums are used to calculate file placement 33 // - move indicates whether srcPath can be removed 34 Import(srcPath, basename string, checksums *utils.ChecksumInfo, move bool, storage ChecksumStorage) (path string, err error) 35 // LegacyPath returns legacy (pre 1.1) path to package file (relative to root) 36 LegacyPath(filename string, checksums *utils.ChecksumInfo) (string, error) 37 // Stat returns Unix stat(2) info 38 Stat(path string) (os.FileInfo, error) 39 // Open returns ReadSeekerCloser to access the file 40 Open(path string) (ReadSeekerCloser, error) 41 // FilepathList returns file paths of all the files in the pool 42 FilepathList(progress Progress) ([]string, error) 43 // Remove deletes file in package pool returns its size 44 Remove(path string) (size int64, err error) 45} 46 47// LocalPackagePool is implemented by PackagePools residing on the same filesystem 48type LocalPackagePool interface { 49 // GenerateTempPath generates temporary path for download (which is fast to import into package pool later on) 50 GenerateTempPath(filename string) (string, error) 51 // Link generates hardlink to destination path 52 Link(path, dstPath string) error 53 // Symlink generates symlink to destination path 54 Symlink(path, dstPath string) error 55 // FullPath generates full path to the file in pool 56 // 57 // Please use with care: it's not supposed to be used to access files 58 FullPath(path string) string 59} 60 61// PublishedStorage is abstraction of filesystem storing all published repositories 62type PublishedStorage interface { 63 // MkDir creates directory recursively under public path 64 MkDir(path string) error 65 // PutFile puts file into published storage at specified path 66 PutFile(path string, sourceFilename string) error 67 // RemoveDirs removes directory structure under public path 68 RemoveDirs(path string, progress Progress) error 69 // Remove removes single file under public path 70 Remove(path string) error 71 // LinkFromPool links package file from pool to dist's pool location 72 LinkFromPool(publishedDirectory, fileName string, sourcePool PackagePool, sourcePath string, sourceChecksums utils.ChecksumInfo, force bool) error 73 // Filelist returns list of files under prefix 74 Filelist(prefix string) ([]string, error) 75 // RenameFile renames (moves) file 76 RenameFile(oldName, newName string) error 77 // SymLink creates a symbolic link, which can be read with ReadLink 78 SymLink(src string, dst string) error 79 // HardLink creates a hardlink of a file 80 HardLink(src string, dst string) error 81 // FileExists returns true if path exists 82 FileExists(path string) (bool, error) 83 // ReadLink returns the symbolic link pointed to by path 84 ReadLink(path string) (string, error) 85} 86 87// FileSystemPublishedStorage is published storage on filesystem 88type FileSystemPublishedStorage interface { 89 // PublicPath returns root of public part 90 PublicPath() string 91} 92 93// PublishedStorageProvider is a thing that returns PublishedStorage by name 94type PublishedStorageProvider interface { 95 // GetPublishedStorage returns PublishedStorage by name 96 GetPublishedStorage(name string) PublishedStorage 97} 98 99// Progress is a progress displaying entity, it allows progress bars & simple prints 100type Progress interface { 101 // Writer interface to support progress bar ticking 102 io.Writer 103 // Start makes progress start its work 104 Start() 105 // Shutdown shuts down progress display 106 Shutdown() 107 // Flush returns when all queued messages are sent 108 Flush() 109 // InitBar starts progressbar for count bytes or count items 110 InitBar(count int64, isBytes bool) 111 // ShutdownBar stops progress bar and hides it 112 ShutdownBar() 113 // AddBar increments progress for progress bar 114 AddBar(count int) 115 // SetBar sets current position for progress bar 116 SetBar(count int) 117 // Printf does printf but in safe manner: not overwriting progress bar 118 Printf(msg string, a ...interface{}) 119 // ColoredPrintf does printf in colored way + newline 120 ColoredPrintf(msg string, a ...interface{}) 121 // PrintfStdErr does printf but in safe manner to stderr 122 PrintfStdErr(msg string, a ...interface{}) 123} 124 125// Downloader is parallel HTTP fetcher 126type Downloader interface { 127 // Download starts new download task 128 Download(ctx context.Context, url string, destination string) error 129 // DownloadWithChecksum starts new download task with checksum verification 130 DownloadWithChecksum(ctx context.Context, url string, destination string, expected *utils.ChecksumInfo, ignoreMismatch bool, maxTries int) error 131 // GetProgress returns Progress object 132 GetProgress() Progress 133 // GetLength returns size by heading object with url 134 GetLength(ctx context.Context, url string) (int64, error) 135} 136 137// ChecksumStorage is stores checksums in some (persistent) storage 138type ChecksumStorage interface { 139 // Get finds checksums in DB by path 140 Get(path string) (*utils.ChecksumInfo, error) 141 // Update adds or updates information about checksum in DB 142 Update(path string, c *utils.ChecksumInfo) error 143} 144