mirror of
https://github.com/0x1d/rcond.git
synced 2025-12-14 10:16:50 +01:00
26 lines
562 B
Go
26 lines
562 B
Go
package system
|
|
|
|
import (
|
|
"fmt"
|
|
"io/ioutil"
|
|
"os"
|
|
"path/filepath"
|
|
)
|
|
|
|
// StoreFile stores a file on the file system at the given path.
|
|
// If the path does not exist, it will be created.
|
|
func StoreFile(path string, content []byte) error {
|
|
// Ensure the directory exists
|
|
dir := filepath.Dir(path)
|
|
if err := os.MkdirAll(dir, 0755); err != nil {
|
|
return fmt.Errorf("failed to create directory: %v", err)
|
|
}
|
|
|
|
// Write the file
|
|
if err := ioutil.WriteFile(path, content, 0644); err != nil {
|
|
return fmt.Errorf("failed to write file: %v", err)
|
|
}
|
|
|
|
return nil
|
|
}
|