mirror of
https://github.com/rwinkhart/libmutton.git
synced 2026-09-03 23:57:27 -04:00
Fail early if adding an entry to a directory that does not exist (or if the directory is a file)
This commit is contained in:
@@ -40,7 +40,15 @@ func TargetIsFile(targetLocation string, errorOnFail bool, failCondition uint8)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// WriteEntry writes entryData to an encrypted file at targetLocation
|
// WriteEntry writes entryData to an encrypted file at targetLocation
|
||||||
func WriteEntry(targetLocation string, entryData []string) {
|
func WriteEntry(targetLocation string, entryData []string, verifyEntryDoesNotExist bool) {
|
||||||
|
if verifyEntryDoesNotExist {
|
||||||
|
_, isAccessible := TargetIsFile(targetLocation, false, 0)
|
||||||
|
if isAccessible {
|
||||||
|
fmt.Println(AnsiError + "Target location already exists" + AnsiReset)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
encryptedBytes := EncryptGPG(entryData)
|
encryptedBytes := EncryptGPG(entryData)
|
||||||
err := os.WriteFile(targetLocation, encryptedBytes, 0600)
|
err := os.WriteFile(targetLocation, encryptedBytes, 0600)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user