Implement synchronized renaming

This commit is contained in:
2024-07-09 23:18:13 -04:00
parent f8d23489c0
commit cef8c47161
2 changed files with 55 additions and 36 deletions
-24
View File
@@ -1,10 +1,5 @@
package backend
import (
"fmt"
"os"
)
// GetOldEntryData decrypts and returns old entry data (with all required lines present)
func GetOldEntryData(targetLocation string, field int) []string {
// ensure targetLocation exists
@@ -21,25 +16,6 @@ func GetOldEntryData(targetLocation string, field int) []string {
}
}
// Rename renames oldLocation to newLocation
func Rename(oldLocation, newLocation string) {
// ensure newLocation does not exist
_, isAccessible := TargetIsFile(newLocation, false, 0)
if isAccessible {
fmt.Println(AnsiError + "\"" + newLocation + "\" already exists" + AnsiReset)
os.Exit(1)
}
// rename oldLocation to newLocation
err := os.Rename(oldLocation, newLocation)
if err != nil {
fmt.Println(AnsiError + "Failed to rename - does the target containing directory exists?" + AnsiReset)
}
// TODO implement synced renaming
Exit(0)
}
// EnsureSliceLength ensures slice is long enough to contain the specified index
func EnsureSliceLength(slice []string, index int) []string {
for len(slice) <= index {