refactor: use helper go functions to handle extracting files from a repository

This standardizes the extraction code and makes it easier to reuse in future implementations of file extraction.

Additionally, this adds a way to extract folders from codebases.
This commit is contained in:
Jose Diaz-Gonzalez
2025-07-23 17:55:45 -04:00
parent 3116880b75
commit 577f46153f
7 changed files with 483 additions and 198 deletions

View File

@@ -195,23 +195,33 @@ func SetPermissions(input SetPermissionInput) error {
return os.Chown(input.Filename, uid, gid)
}
// TouchDir creates an empty directory at the specified path
func TouchDir(filename string) error {
mode := os.FileMode(0700)
return os.MkdirAll(filename, mode)
}
// TouchFile creates an empty file at the specified path
func TouchFile(filename string) error {
mode := os.FileMode(0600)
file, err := os.OpenFile(filename, os.O_RDWR|os.O_CREATE|os.O_TRUNC, mode)
if err != nil {
return err
return fmt.Errorf("Error opening file %v for creation: %v", filename, err)
}
defer file.Close()
if err := file.Chmod(mode); err != nil {
return err
return fmt.Errorf("Error setting chown for new file %v: %v", filename, err)
}
return SetPermissions(SetPermissionInput{
if err := SetPermissions(SetPermissionInput{
Filename: filename,
Mode: mode,
})
}); err != nil {
return fmt.Errorf("Error setting permissions for new file %v: %v", filename, err)
}
return nil
}
// WriteSliceToFile writes a slice of strings to a file