file

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 11, 2025 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Overview

Package file implements utility routines for file operations and system interactions.

It provides functions to search for files, list block devices, and search mountpoints on both macOS and Linux systems.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindUserData

func FindUserData() (string, error)

FindUserData searches for the config file on the system. On macOS, it searches within the "/Volumes" directory. On Linux, it lists block devices and searches their mountpoints and their children mountpoints. If the file is found, its path is returned. If an error occurs during the search, it is returned.

func GetFilePath

func GetFilePath(rootDir string, fileName string) (string, error)

GetFilePath searches for a file with the specified name starting from the rootDir. It traverses the directory tree and returns the path of the first matching file found. Hidden directories and files are skipped during the search. If the file is found, its path is returned. If an error occurs during the search, it is returned.

func SearchMountpoints

func SearchMountpoints(mountpoints []string, fileName string) (string, error)

SearchMountpoints searches for a file with the specified name in the provided mountpoints iterating over them, ignoring certain paths. For valid mountpoints, it calls GetFilePath to find the "user-data" file. If the file is found, its path is returned. If an error occurs, it is returned.

Types

type BlockDevices

type BlockDevices struct {
	Blockdevices []struct {
		Name        string   `json:"name"`
		MajMin      string   `json:"maj:min"`
		Rm          bool     `json:"rm"`
		Size        string   `json:"size"`
		Ro          bool     `json:"ro"`
		Type        string   `json:"type"`
		Mountpoints []string `json:"mountpoints"`
		Children    []struct {
			Name        string   `json:"name"`
			MajMin      string   `json:"maj:min"`
			Rm          bool     `json:"rm"`
			Size        string   `json:"size"`
			Ro          bool     `json:"ro"`
			Type        string   `json:"type"`
			Mountpoints []string `json:"mountpoints"`
		} `json:"children,omitempty"`
	} `json:"blockdevices"`
}

BlockDevices is the representation of the block devices on a Linux system as returned by the `lsblk` command, containing information about each block device. If the block device has children (e.g., partitions), they are also included with similar information.

func ListBlockDevices

func ListBlockDevices() (BlockDevices, error)

ListBlockDevices returns a list of block devices on a Linux system by executing the `lsblk` command with the `--json` flag, parsing it's output into a BlockDevices struct. If the command execution or JSON parsing fails, an error is returned.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL