Documentation ¶
Index ¶
- func AtomicSwap(sourcePath, destinationPath string) error
- func CopyFile(sourcePath, destinationPath string) error
- func CreateDirectory(directoryPath string) error
- func DeleteDirectory(directoryPath string) error
- func DeleteFile(filePath string) error
- func DirectoryExists(directoryPath string) bool
- func FileExists(filePath string) bool
- func GetDiskInfo(partitionPath string) (types.BaseInfo, error)
- func GetDiskList() ([]types.DiskInfo, error)
- func GetFile(filePath string, fullPath bool) (types.FileInfo, error)
- func GetFileDiff(firstFile, secondFile string) (types.FileDiffInfo, error)
- func GetFileExtension(filePath string) string
- func GetFileList(directory string, recursive, fullPaths bool) ([]types.FileInfo, error)
- func GetFileSize(filePath string) int64
- func GetFilesystemInfo(path string) map[string]string
- func GetHumanSize(size int64) string
- func GetPartitionList(diskPath string) ([]types.PartitionInfo, error)
- func IsDirectory(dirPath string) bool
- func IsFile(filePath string) bool
- func IsMounted(source string, destination string) (bool, error)
- func ListDirectories(directoryPath string) ([]string, error)
- func Mount(source, destination, fsType, data string, mode uintptr) error
- func MountBind(src, dest string) error
- func MountFuseOverlay(targetDir, lowerDir, upperDir, workDir string) (err error)
- func MountOverlay(lowerDir, upperDir, workDir string) error
- func MoveFile(sourcePath, destinationPath string) error
- func Unmount(target string) error
- func UnmountFuseOverlay(targetDir string) (err error)
- func WriteFileContent(filePath, content string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AtomicSwap ¶
AtomicSwap atomically swaps two files or directories
Example:
err := fs.AtomicSwap("/tmp/file1", "/tmp/file2") if err != nil { fmt.Printf("Error swapping files: %v", err) return }
func CopyFile ¶
CopyFile copies the contents of one file to another
Example:
err := fs.CopyFile("/tmp/batman", "/tmp/robin") if err != nil { fmt.Printf("Error copying file: %v", err) return }
func CreateDirectory ¶
CreateDirectory creates a new directory
Example:
err := fs.CreateDirectory("/tmp/batman") if err != nil { fmt.Printf("Error creating directory: %v", err) return }
func DeleteDirectory ¶
DeleteDirectory deletes a directory and its contents
Example:
err := fs.DeleteDirectory("/tmp/batman") if err != nil { fmt.Printf("Error deleting directory: %v", err) return }
func DeleteFile ¶
DeleteFile deletes a file
Example:
err := fs.DeleteFile("/tmp/batman") if err != nil { fmt.Printf("Error deleting file: %v", err) return }
func DirectoryExists ¶
DirectoryExists checks if a directory exists
Example:
if fs.DirectoryExists("/tmp/batman") { fmt.Println("The directory exists!") }
func FileExists ¶
FileExists checks if a file exists
Example:
if fs.FileExists("/tmp/batman") { fmt.Println("The file exists!") }
func GetDiskInfo ¶
GetDiskInfo returns information about a specific disk partition
Example:
info, err := fs.GetDiskInfo("/dev/sda1") if err != nil { fmt.Printf("Error getting partition info: %v", err) return } fmt.Printf("Path: %s\n", info.Path) fmt.Printf("Size: %d\n", info.Size) fmt.Printf("HumanSize: %s\n", info.HumanSize)
func GetDiskList ¶
GetDiskList returns a list of disks on the system
Example:
disks, err := fs.GetDiskList() if err != nil { fmt.Printf("Error getting disk list: %v", err) return } for _, disk := range disks { fmt.Printf("Disk: %s\n", disk.Path) fmt.Printf("Size: %d\n", disk.Size) fmt.Printf("HumanSize: %s\n", disk.HumanSize) for _, partition := range disk.Partitions { fmt.Printf("Partition: %s\n", partition.Path) fmt.Printf("Size: %d\n", partition.Size) fmt.Printf("HumanSize: %s\n", partition.HumanSize) fmt.Printf("Filesystem: %s\n", partition.Filesystem) fmt.Printf("Mountpoint: %s\n", partition.Mountpoint) fmt.Printf("Label: %s\n", partition.Label) fmt.Printf("UUID: %s\n", partition.UUID) fmt.Printf("PARTUUID: %s\n", partition.PARTUUID) fmt.Printf("Flags: %v\n", partition.Flags) } }
func GetFile ¶
GetFile returns the file info of the specified file. If fullPath is true, the full path of the file will be returned instead of the relative path.
Example:
file, err := fs.GetFile("/batmans/cave/batmobile.txt", false) if err != nil { fmt.Printf("Error: %v\n", err) return } fmt.Printf("Path: %s\n", file.Path) fmt.Printf("Size: %d\n", file.Size) fmt.Printf("Permissions: %s\n", file.Permissions.String())
func GetFileDiff ¶
func GetFileDiff(firstFile, secondFile string) (types.FileDiffInfo, error)
GetFileDiff compares the content of two files and returns the changes
Example:
diff, err := fs.GetFileDiff("/tmp/batman", "/tmp/robin") if err != nil { fmt.Printf("Error getting file diff: %v", err) return } fmt.Printf("Added lines: %v\n", diff.AddedLines) fmt.Printf("Removed lines: %v\n", diff.RemovedLines)
func GetFileExtension ¶
GetFileExtension returns the extension of the given file
Example:
extension := fs.GetFileExtension("/batmans/cave/batmobile.txt") fmt.Printf("Extension: %s\n", extension)
func GetFileList ¶
GetFileList returns a list of files in the specified directory. If recursive is true, the function will recursively search for files, if fullPaths is true, the full path of the file will be returned instead of the relative path.
Example:
fileList, err := fs.GetFileList("/batmans/cave", true, false) if err != nil { fmt.Printf("Error: %v\n", err) return } for _, file := range fileList { fmt.Printf("Path: %s\n", file.Path) fmt.Printf("Size: %d\n", file.Size) fmt.Printf("Permissions: %s\n", file.Permissions.String()) fmt.Printf("Extension: %s\n", file.Extension) }
func GetFileSize ¶
GetFileSize returns the size of the specified file in bytes
Example:
size := fs.GetFileSize("/batmans/cave/batmobile.txt") fmt.Printf("Size: %d\n", size)
func GetFilesystemInfo ¶
GetFilesystemInfo returns information about the filesystem of a file or partition by reading from /etc/mtab.
func GetHumanSize ¶
GetHumanSize converts the size from bytes to a human-readable format. For example, 1024 bytes would be converted to "1 kB".
Example:
fmt.Println(GetHumanSize(1024)) // 1 kB
func GetPartitionList ¶
func GetPartitionList(diskPath string) ([]types.PartitionInfo, error)
GetPartitionList returns a list of disk partitions on the specified disk
Example:
partitions, err := fs.GetPartitionList("/dev/sda") if err != nil { fmt.Printf("Error getting partition list: %v", err) return } for _, partition := range partitions { fmt.Printf("Partition: %s\n", partition.Path) fmt.Printf("Size: %d\n", partition.Size) fmt.Printf("HumanSize: %s\n", partition.HumanSize) }
func IsDirectory ¶
IsDirectory checks whether the given path is a directory
Example:
if fs.IsDirectory("/batmans/cave") { fmt.Println("It's a directory!") }
func IsFile ¶
IsFile checks whether the given path is a regular file
Example:
if fs.IsFile("/batmans/cave/batmobile.txt") { fmt.Println("It's a file!") }
func IsMounted ¶
IsMounted checks if the given source path is mounted in the given destination path. It does so by reading the /proc/mounts file.
Example:
mounted, err := fs.IsMounted("tmpfs", "/tmp") if err != nil { fmt.Printf("Error checking if /tmp is mounted: %v", err) return } fmt.Printf("/tmp is mounted: %v", mounted)
func ListDirectories ¶
ListDirectories returns a list of directories in the specified directory
Example:
directories, err := fs.ListDirectories("/tmp") if err != nil { fmt.Printf("Error: %v\n", err) return } for _, directory := range directories { fmt.Printf("Directory: %s\n", directory) }
func Mount ¶
Mount mounts the given source path in the given destination path. It also creates the destination path if it does not exist. An error is returned if the source path does not exist.
Notes (for developers):
Avoid mapping the fsType into a custom type, as it would require further maintenance once a new filesystem type is added to Vanilla OS.
Example:
err := fs.Mount("/dev/sda1", "/mnt", "ext4", "", syscall.MS_RDONLY) if err != nil { fmt.Printf("Error mounting /dev/sda1: %v", err) return }
func MountBind ¶
MountBind mounts bind the given source path in the given destination path.
Notes:
This is just a wrapper of the Mount function, for convenience.
Example:
err := fs.MountBind("/bruce", "/batman") if err != nil { fmt.Printf("Error bind mounting /batman: %v", err) return }
func MountFuseOverlay ¶
MountFuseOverlay mounts the given lower, upper and work directories in the given destination path as an overlay filesystem using fuse-overlayfs.
Notes:
This implementation uses the fuse-overlayfs command-line tool, if that is not available in the system, this function will return an error.
Example:
err := fs.MountFuseOverlay("/batman", "/batman/lower", "/batman/upper", "/batman/work") if err != nil { fmt.Printf("Error fuse-overlayfs mounting /batman: %v", err) return }
func MountOverlay ¶
MountOverlay mounts the given lower, upper and work directories in the given destination path as an overlay filesystem.
Notes:
This is just a wrapper of the Mount function, for convenience.
Example:
err := fs.MountOverlay("/batman/lower", "/batman/upper", "/batman/work") if err != nil { fmt.Printf("Error overlay mounting /batman: %v", err) return }
func MoveFile ¶
MoveFile moves a file from one location to another
Example:
err := fs.MoveFile("/tmp/batman", "/tmp/robin") if err != nil { fmt.Printf("Error moving file: %v", err) return }
func Unmount ¶
Unmount unmounts the given path. An error is returned if the path is not mounted.
Example:
err := fs.Unmount("/mnt") if err != nil { fmt.Printf("Error unmounting /mnt: %v", err) return }
func UnmountFuseOverlay ¶
UnmountFuseOverlay unmounts the given path using the fuse-overlayfs command- line tool. An error is returned if the path is not mounted.
Notes:
This implementation uses the fuse-overlayfs command-line tool, if that is not available in the system, this function will return an error.
Example:
err := fs.UnmountFuseOverlay("/batman") if err != nil { fmt.Printf("Error fuse-overlayfs unmounting /batman: %v", err) return }
func WriteFileContent ¶
WriteFileContent writes content to the specified file
Example:
err := fs.WriteFileContent("/tmp/batman", "I'm Batman!") if err != nil { fmt.Printf("Error writing file content: %v", err) return }
Types ¶
This section is empty.