Documentation
¶
Index ¶
- type OsProxy
- type RealOS
- func (RealOS) Create(name string) (*os.File, error)
- func (RealOS) EvalSymlinks(path string) (string, error)
- func (RealOS) Lstat(name string) (os.FileInfo, error)
- func (RealOS) MkdirAll(path string, perm os.FileMode) error
- func (RealOS) Open(name string) (*os.File, error)
- func (RealOS) OpenFile(name string, flag int, perm os.FileMode) (*os.File, error)
- func (RealOS) Readlink(name string) (string, error)
- func (RealOS) Remove(name string) error
- func (RealOS) Rename(oldpath, newpath string) error
- func (RealOS) Symlink(oldname, newname string) error
- type ZipManager
- func (z *ZipManager) UnZip(zipPth, intoDir string) error
- func (z *ZipManager) ZipDir(sourceDirPth, destinationZipPth string, isContentOnly bool) error
- func (z *ZipManager) ZipDirs(sourceDirPths []string, destinationZipPth string) error
- func (z *ZipManager) ZipFile(sourceFilePth, destinationZipPth string) error
- func (z *ZipManager) ZipFiles(sourceFilePths []string, destinationZipPth string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type OsProxy ¶
type OsProxy interface {
Lstat(name string) (os.FileInfo, error)
Readlink(name string) (string, error)
Open(name string) (*os.File, error)
Create(name string) (*os.File, error)
OpenFile(name string, flag int, perm os.FileMode) (*os.File, error)
Remove(name string) error
Rename(oldpath, newpath string) error
MkdirAll(path string, perm os.FileMode) error
Symlink(oldname, newname string) error
EvalSymlinks(path string) (string, error)
}
OsProxy defines the subset of OS operations used by ZipManager.
type RealOS ¶
type RealOS struct{}
RealOS is the default implementation that delegates to the real os package.
type ZipManager ¶
type ZipManager struct {
// contains filtered or unexported fields
}
ZipManager provides zip and unzip operations using Go stdlib.
func NewZipManager ¶
func NewZipManager(pathChecker pathutil.PathChecker) *ZipManager
NewZipManager creates a ZipManager backed by the real OS.
func (*ZipManager) UnZip ¶
func (z *ZipManager) UnZip(zipPth, intoDir string) error
UnZip extracts the zip archive at zipPth into intoDir, restoring permissions and symlinks. Entries with path-traversal components (e.g. "../../escape") are rejected and an error is returned immediately; no further entries are extracted after a traversal is detected. Rejection is by substring: any entry whose name contains ".." anywhere is refused, including otherwise-legitimate names like "foo..bar". This is broader than strict path-component traversal, but is required for the repo's static analysis to recognise the sanitizer.
func (*ZipManager) ZipDir ¶
func (z *ZipManager) ZipDir(sourceDirPth, destinationZipPth string, isContentOnly bool) error
ZipDir zips sourceDirPth into destinationZipPth. isContentOnly=false: archive contains the directory under its own basename (e.g. "mydir/file.txt"). isContentOnly=true: archive contains the directory's contents directly (e.g. "file.txt"). Directory modification times are preserved. Symlinks are stored as symlinks (not followed). If destinationZipPth has no file extension, ".zip" is appended.
func (*ZipManager) ZipDirs ¶
func (z *ZipManager) ZipDirs(sourceDirPths []string, destinationZipPth string) error
ZipDirs zips multiple directories into a single archive, each under its own basename. When two entries in sourceDirPths share the same basename (e.g. "/a/shared" and "/b/shared"), their contents are merged: files unique to either directory are preserved, and conflicting files (same relative path) resolve in favour of the last directory in the list. If destinationZipPth has no file extension, ".zip" is appended.
func (*ZipManager) ZipFile ¶
func (z *ZipManager) ZipFile(sourceFilePth, destinationZipPth string) error
ZipFile zips a single file into destinationZipPth. If destinationZipPth has no file extension, ".zip" is appended.
func (*ZipManager) ZipFiles ¶
func (z *ZipManager) ZipFiles(sourceFilePths []string, destinationZipPth string) error
ZipFiles zips multiple files into destinationZipPth without preserving directory structure. Each file is stored under its base name only. Symlinks are stored as symlinks (not followed). If two source files share the same base name, an error is returned before the destination file is created. If destinationZipPth has no file extension, ".zip" is appended.