Documentation
¶
Overview ¶
Package image provides high-level access to Harbor / docker-save image archives: metadata scanning, merged filesystem views, directory listing without extraction, selective extraction of single entries, and full merged rootfs extraction. It also reads QEMU qcow2 disk images through the same surface.
Index ¶
- func ApplyImage(imageTarPath string, meta *types.ImageMetadata, outputDir string, ...) error
- func BuildFileSystem(imageTarPath string, meta *types.ImageMetadata) (*fsview.Node, error)
- func DetectInput(path string) string
- func ExtractDiskPath(path, vp, destPath string, bufferSize int) (int, error)
- func ExtractDiskVolumes(path, outputDir string, bufferSize int) ([]string, error)
- func ExtractPath(imageTarPath string, meta *types.ImageMetadata, sourcePath, destPath string, ...) (int, error)
- func FormatListing(root *fsview.Node, target string) (string, error)
- func IsDiskImage(path string) bool
- func IsOCILayout(path string) bool
- func PrepareOutputDir(outputDir string, force bool) error
- func ReadArchiveFile(path string, meta *types.ImageMetadata, sourcePath string) (io.ReadCloser, int64, error)
- func ReadDiskFile(path, vp string) (io.ReadCloser, int64, error)
- func ScanImageMetadata(imageTarPath string, sel Selection) (*types.ImageMetadata, error)
- func WriteConfigYAML(outputDir string, meta *types.ImageMetadata) error
- type DiskInfo
- type DiskMetadata
- type DiskVolume
- type FileEntry
- type ProgressReporter
- type Selection
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyImage ¶
func ApplyImage(imageTarPath string, meta *types.ImageMetadata, outputDir string, bufferSize int, progress ProgressReporter) error
func BuildFileSystem ¶
BuildFileSystem merges all layers of the image into an in-memory tree without writing anything to disk.
func DetectInput ¶ added in v0.4.0
DetectInput returns the input class of path by content: "disk" for a virtual disk container or raw filesystem image, "archive" for a plain archive, and "" for unsupported files.
func ExtractDiskPath ¶ added in v0.4.0
ExtractDiskPath copies the file or directory at virtual path vp out to dest.
func ExtractDiskVolumes ¶ added in v0.4.0
ExtractDiskVolumes extracts every filesystem volume in the image. With several volumes each lands in its own subdirectory under outputDir; a single volume goes straight into outputDir. It returns the extracted volume names.
func ExtractPath ¶
func ExtractPath(imageTarPath string, meta *types.ImageMetadata, sourcePath, destPath string, bufferSize int) (int, error)
ExtractPath copies a single file or directory from the merged image filesystem to destPath, streaming only the entries that belong to the selection instead of extracting the whole image.
Semantics mirror cp: a directory source copied into an existing directory lands at destPath/<basename>, while a non-existent destination receives the copy directly. Extracting the image root ("/" or ".") puts its contents into destPath itself. Returns the number of entries written.
func FormatListing ¶
FormatListing renders the merged image filesystem at target the way `ls -al` would: one long-format line per entry, plus a total block line for directories. target "" or "/" lists the image root.
func IsDiskImage ¶ added in v0.4.0
IsDiskImage reports whether path is a virtual disk image (qcow2/vmdk/vhd/ vhdx/vdi/parallels/qed/qcow1/vma/sif/ova/ovf/ffu/wim/esd/swm) or a raw filesystem image (ext4/xfs/squashfs/ISO9660/UDF/exFAT/EROFS/FAT). Detection is content based (file magic), not by filename extension. Disk images are a different input class from the tar/zip archives handled elsewhere.
func IsOCILayout ¶ added in v0.4.0
IsOCILayout reports whether path is a directory containing an OCI image layout (an oci-layout file plus an index.json). An OCI layout is read through the same archive pipeline as docker save archives, so it is a directory rather than a disk image.
func PrepareOutputDir ¶
func ReadArchiveFile ¶ added in v0.4.0
func ReadArchiveFile(path string, meta *types.ImageMetadata, sourcePath string) (io.ReadCloser, int64, error)
ReadArchiveFile opens the content of a single regular file inside an archive image (tar/tar.gz/tgz/zip/7z/cpio/rar), following hardlink and symlink nodes to the regular file they point at. The returned reader must be closed to release the opened layer; size is the file length in bytes.
func ReadDiskFile ¶ added in v0.4.0
func ReadDiskFile(path, vp string) (io.ReadCloser, int64, error)
ReadDiskFile opens the content of a single regular file inside a disk image (qcow2/vmdk/vhd/vhdx/ova/...) at virtual path vp. The returned reader must be closed to release the image, its volumes and the opened file; size is the file length in bytes. Symlinks are not followed; use a filesystem path.
func ScanImageMetadata ¶
func ScanImageMetadata(imageTarPath string, sel Selection) (*types.ImageMetadata, error)
func WriteConfigYAML ¶
func WriteConfigYAML(outputDir string, meta *types.ImageMetadata) error
Types ¶
type DiskInfo ¶ added in v0.4.0
type DiskInfo struct {
Name string `json:"name"`
Format string `json:"format"`
VirtualSize int64 `json:"virtual_size"`
Filesystem string `json:"filesystem,omitempty"`
Volume string `json:"volume,omitempty"`
Volumes []DiskVolume `json:"volumes,omitempty"`
}
DiskInfo describes one disk inside an opened image: a qcow2/vmdk file, or a single .vmdk extracted from an OVA.
type DiskMetadata ¶ added in v0.4.0
type DiskMetadata struct {
Disks []DiskInfo `json:"disks"`
}
DiskMetadata summarizes a disk image: one or more disks, each with its partitions and LVM logical volumes.
func ScanDiskMetadata ¶ added in v0.4.0
func ScanDiskMetadata(path string) (*DiskMetadata, error)
ScanDiskMetadata inspects a disk image without extracting anything.
type DiskVolume ¶ added in v0.4.0
type DiskVolume struct {
Name string `json:"name"`
Kind string `json:"kind"` // "partition" | "lvm" | "disk"
Start int64 `json:"start"`
Size int64 `json:"size"`
FSType string `json:"fs_type,omitempty"` // "ext4" | "xfs"
}
DiskVolume is one extractable region on a disk image: an MBR/GPT partition or an LVM logical volume.
func (DiskVolume) String ¶ added in v0.4.0
func (v DiskVolume) String() string
String renders a compact "name(fs)" form so CLI listings stay legible.
type FileEntry ¶
type FileEntry struct {
Name string `json:"name"`
Type string `json:"type"`
Mode string `json:"mode"`
Size int64 `json:"size"`
ModTime time.Time `json:"mod_time"`
Target string `json:"target,omitempty"`
FSType string `json:"fs_type,omitempty"` // filesystem of a disk/volume row
}
FileEntry is a structured description of one entry in the merged image filesystem — the machine-friendly counterpart of a FormatListing line.
func ListArchive ¶ added in v0.4.0
ListArchive lists the directory (or single file) at treePath inside an archive image, caching the result so repeated listings skip re-scanning the archive and re-building the merged filesystem tree.
type ProgressReporter ¶
type ProgressReporter interface {
SetLayer(string)
AddLayer()
MarkDone()
}