Documentation ¶
Overview ¶
Provide a helper for directory operations.
Provide helper functions related to file.
Provide helper functions.
Index ¶
- Constants
- func AreFilesIdentical(filepath1, filepath2 string) (bool, error)
- func ClearCacheControlOnGcsObject(gcsObjPath string) error
- func CloseFile(file *os.File)
- func CloseFileShouldNotThrowError(file *os.File, t *testing.T)
- func CopyDir(srcDirPath string, destDirPath string) (err error)
- func CopyDirWithRootPermission(srcDirPath string, destDirPath string) (err error)
- func CopyFile(srcFileName, newFileName string) (err error)
- func CopyFileAllowOverwrite(srcFileName, newFileName string) (err error)
- func CopyFileInBucket(srcfilePath, destFilePath, bucket string, t *testing.T)
- func CreateDirectory(dirPath string, t *testing.T)
- func CreateDirectoryWithNFiles(numberOfFiles int, dirPath string, prefix string, t *testing.T)
- func CreateFile(filePath string, filePerms os.FileMode, t *testing.T) (f *os.File)
- func CreateFileOfSize(fileSize int64, filePath string, t *testing.T)
- func CreateFileWithContent(filePath string, filePerms os.FileMode, content string, t *testing.T)
- func CreateManagedFoldersInBucket(managedFolderPath, bucket string, t *testing.T)
- func CreateSymLink(filePath, symlink string, t *testing.T)
- func DeleteGcsObject(gcsObjPath string) error
- func DeleteManagedFoldersInBucket(managedFolderPath, bucket string, t *testing.T)
- func DirSizeMiB(dirPath string) (dirSizeMB int64, err error)
- func DownloadGcsObject(gcsObjPath, localPath string) error
- func ExecuteGcloudCommandf(format string, args ...any) ([]byte, error)
- func ExecuteGsutilCommandf(format string, args ...any) ([]byte, error)
- func GenerateRandomData(sizeInBytes int64) ([]byte, error)
- func GetGcsObjectSize(gcsObjPath string) (int, error)
- func MoveDir(srcDirPath string, destDirPath string) (err error)
- func MoveFile(srcFilePath string, destDirPath string) (err error)
- func ReadChunkFromFile(filePath string, chunkSize int64, offset int64, flag int) (chunk []byte, err error)
- func ReadDirectory(dirPath string, t *testing.T) (entries []os.DirEntry)
- func ReadFile(filePath string) (content []byte, err error)
- func ReadFileSequentially(filePath string, chunkSize int64) (content []byte, err error)
- func RemoveDir(dirPath string)
- func RemoveFile(filePath string)
- func RenameDir(dirName string, newDirName string) (err error)
- func RenameFile(fileName string, newFileName string) (err error)
- func StatFile(file string) (*fs.FileInfo, error)
- func SyncFile(fh *os.File, t *testing.T)
- func UploadGcsObject(localPath, gcsObjPath string, uploadGzipEncoded bool) error
- func ValidateNoFileOrDirError(path string, t *testing.T)
- func VerifyCountOfDirectoryEntries(expected, got int, t *testing.T)
- func VerifyDirectoryEntry(entry os.DirEntry, dirName string, t *testing.T)
- func VerifyFileEntry(entry os.DirEntry, fileName string, size int64, t *testing.T)
- func VerifyReadFile(filePath, expectedContent string, t *testing.T)
- func VerifyReadLink(expectedTarget, symlinkName string, t *testing.T)
- func VerifyStatFile(filePath string, fileSize int64, filePerms os.FileMode, t *testing.T)
- func WriteAt(content string, offset int64, fh *os.File, t *testing.T)
- func WriteChunkOfRandomBytesToFile(file *os.File, chunkSize int, offset int64) error
- func WriteFile(fileName string, content string) (err error)
- func WriteFileInAppendMode(fileName string, content string) (err error)
- func WriteFileSequentially(filePath string, fileSize int64, chunkSize int64) (err error)
- func WriteWithoutClose(fh *os.File, content string, t *testing.T)
Constants ¶
const ( OneKiB = 1024 OneMiB = OneKiB * OneKiB // ChunkSizeForContentComparison is currently set to 1 MiB. ChunkSizeForContentComparison int = OneMiB )
const DirPermission_0755 = 0755
const FilePermission_0400 = 0400
const FilePermission_0600 = 0600
const FilePermission_0777 = 0777
const MiB = 1024 * 1024
Variables ¶
This section is empty.
Functions ¶
func AreFilesIdentical ¶
Finds if two local files have identical content (equivalnt to binary diff). Needs (a) both files to exist, (b)read permission on both the files, (c) both inputs to be proper files, i.e. directories not supported. Compares file names first. If different, compares sizes next. If sizes match, then compares the contents of both the files. Returns true if no error and files match. Returns false if files don't match (captures reason for mismatch in err) or if any other error.
func ClearCacheControlOnGcsObject ¶
Clears cache-control attributes on given GCS object (with path without 'gs://'). Fails if the file doesn't exist or permission to modify object's metadata is not available. Uses 'gsutil setmeta -h "Cache-Control:" gs://<path>' Preferred approach is 'gcloud storage objects update gs://gs://gcsObjPath --cache-control=' ' ' but it doesn't work on kokoro VM.
func CopyFileAllowOverwrite ¶
func CopyFileInBucket ¶
func CreateDirectory ¶
func CreateFile ¶
func CreateFileOfSize ¶
CreateFileOfSize creates a file of given size with random data.
func CreateFileWithContent ¶
func CreateSymLink ¶
func DeleteGcsObject ¶
Deletes a given GCS object (with path without 'gs://'). Fails if the object doesn't exist or permission to delete object is not available. Uses 'gsutil rm gs://gcsObjPath' Alternative 'gcloud storage rm gs://gcsObjPath' but it doesn't work on kokoro VM.
func DirSizeMiB ¶
func DownloadGcsObject ¶
Downloads given GCS object (with path without 'gs://') to localPath. Fails if the object doesn't exist or permission to read object is not available. Uses 'gsutil cp gs://gcsObjPath localPath' Alternative 'gcloud storage cp gs://gcsObjPath localPath' but it doesn't work on kokoro VM.
func ExecuteGcloudCommandf ¶
Executes any given gcloud command with given args.
func ExecuteGsutilCommandf ¶
Executes any given gsutil command with given args.
func GenerateRandomData ¶
GenerateRandomData generates random data that can be used to write to a file.
func GetGcsObjectSize ¶
Returns size of a give GCS object with path (without 'gs://'). Fails if the object doesn't exist or permission to read object's metadata is not available. Uses 'gsutil du -s gs://gcsObjPath'. Alternative 'gcloud storage du -s gs://gcsObjPath', but it doesn't work on kokoro VM.
func ReadChunkFromFile ¶
func ReadFileSequentially ¶
func RemoveFile ¶
func RemoveFile(filePath string)
func RenameFile ¶
func UploadGcsObject ¶
Uploads given local file to GCS object (with path without 'gs://'). Fails if the file doesn't exist or permission to write to object/bucket is not available. Uses 'gsutil cp localPath gs://gcsObjPath' Alternative 'gcloud storage cp localPath gs://gcsObjPath' but it doesn't work on kokoro VM.
func VerifyDirectoryEntry ¶
func VerifyFileEntry ¶
func VerifyReadFile ¶
func VerifyReadLink ¶
func VerifyStatFile ¶
func WriteChunkOfRandomBytesToFile ¶
Write data of chunkSize in file at given offset.
func WriteFileInAppendMode ¶
func WriteFileSequentially ¶
Types ¶
This section is empty.