mirror of
https://github.com/rwinkhart/libmutton.git
synced 2026-08-28 04:46:42 -04:00
Rename "backend" package to "core"
This commit is contained in:
+17
-17
@@ -6,14 +6,14 @@ import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/rwinkhart/MUTN/src/backend"
|
||||
"github.com/rwinkhart/libmutton/core"
|
||||
)
|
||||
|
||||
// getModTimes returns a list of all entry modification times
|
||||
func getModTimes(entryList []string) []int64 {
|
||||
var modList []int64
|
||||
for _, file := range entryList {
|
||||
modTime, _ := os.Stat(backend.TargetLocationFormat(file))
|
||||
modTime, _ := os.Stat(core.TargetLocationFormat(file))
|
||||
modList = append(modList, modTime.ModTime().Unix())
|
||||
}
|
||||
|
||||
@@ -23,9 +23,9 @@ func getModTimes(entryList []string) []int64 {
|
||||
// genDeviceIDList returns a pointer to a slice of all registered device IDs
|
||||
func genDeviceIDList() *[]fs.DirEntry {
|
||||
// create a slice of all registered devices
|
||||
deviceIDList, err := os.ReadDir(backend.ConfigDir + backend.PathSeparator + "devices")
|
||||
deviceIDList, err := os.ReadDir(core.ConfigDir + core.PathSeparator + "devices")
|
||||
if err != nil {
|
||||
fmt.Println(backend.AnsiError + "Failed to read the devices directory: " + err.Error() + backend.AnsiReset)
|
||||
fmt.Println(core.AnsiError + "Failed to read the devices directory: " + err.Error() + core.AnsiReset)
|
||||
os.Exit(1)
|
||||
}
|
||||
return &deviceIDList
|
||||
@@ -48,7 +48,7 @@ func ShearLocal(targetLocationIncomplete, clientDeviceID string) string {
|
||||
if onServer {
|
||||
for _, device := range *deviceIDList {
|
||||
if device.Name() != clientDeviceID {
|
||||
_, err := os.Create(backend.ConfigDir + backend.PathSeparator + "deletions" + backend.PathSeparator + device.Name() + FSSpace + strings.ReplaceAll(targetLocationIncomplete, "/", FSPath))
|
||||
_, err := os.Create(core.ConfigDir + core.PathSeparator + "deletions" + core.PathSeparator + device.Name() + FSSpace + strings.ReplaceAll(targetLocationIncomplete, "/", FSPath))
|
||||
if err != nil {
|
||||
// do not print error as there is currently no way of seeing server-side errors
|
||||
// failure to add the target to the deletions list will exit the program and result in a client re-uploading the target (non-critical)
|
||||
@@ -59,13 +59,13 @@ func ShearLocal(targetLocationIncomplete, clientDeviceID string) string {
|
||||
}
|
||||
|
||||
// get the full targetLocation path and remove the target
|
||||
targetLocationComplete := backend.TargetLocationFormat(targetLocationIncomplete)
|
||||
targetLocationComplete := core.TargetLocationFormat(targetLocationIncomplete)
|
||||
if !onServer { // error if target does not exist on client, needed because os.RemoveAll does not return an error if target does not exist
|
||||
backend.TargetIsFile(targetLocationComplete, true, 0)
|
||||
core.TargetIsFile(targetLocationComplete, true, 0)
|
||||
}
|
||||
err := os.RemoveAll(targetLocationComplete)
|
||||
if err != nil {
|
||||
fmt.Println(backend.AnsiError + "Failed to remove local target: " + err.Error() + backend.AnsiReset)
|
||||
fmt.Println(core.AnsiError + "Failed to remove local target: " + err.Error() + core.AnsiReset)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
@@ -81,24 +81,24 @@ func ShearLocal(targetLocationIncomplete, clientDeviceID string) string {
|
||||
// this function should only be used directly by the server binary
|
||||
func RenameLocal(oldLocationIncomplete, newLocationIncomplete string, verifyOldLocationExists bool) {
|
||||
// get full paths for both locations
|
||||
oldLocation := backend.TargetLocationFormat(oldLocationIncomplete)
|
||||
newLocation := backend.TargetLocationFormat(newLocationIncomplete)
|
||||
oldLocation := core.TargetLocationFormat(oldLocationIncomplete)
|
||||
newLocation := core.TargetLocationFormat(newLocationIncomplete)
|
||||
|
||||
if verifyOldLocationExists {
|
||||
backend.TargetIsFile(oldLocation, true, 0)
|
||||
core.TargetIsFile(oldLocation, true, 0)
|
||||
}
|
||||
|
||||
// ensure newLocation does not exist
|
||||
_, isAccessible := backend.TargetIsFile(newLocation, false, 0)
|
||||
_, isAccessible := core.TargetIsFile(newLocation, false, 0)
|
||||
if isAccessible {
|
||||
fmt.Println(backend.AnsiError + "\"" + newLocation + "\" already exists" + backend.AnsiReset)
|
||||
fmt.Println(core.AnsiError + "\"" + newLocation + "\" already exists" + core.AnsiReset)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// rename oldLocation to newLocation
|
||||
err := os.Rename(oldLocation, newLocation)
|
||||
if err != nil {
|
||||
fmt.Println(backend.AnsiError + "Failed to rename - does the target containing directory exist?" + backend.AnsiReset)
|
||||
fmt.Println(core.AnsiError + "Failed to rename - does the target containing directory exist?" + core.AnsiReset)
|
||||
}
|
||||
|
||||
// do not exit program, as this function is used as part of RenameRemoteFromClient
|
||||
@@ -108,14 +108,14 @@ func RenameLocal(oldLocationIncomplete, newLocationIncomplete string, verifyOldL
|
||||
// this function should only be used directly by the server binary
|
||||
func AddFolderLocal(targetLocationIncomplete string) {
|
||||
// get the full targetLocation path and create the target
|
||||
targetLocationComplete := backend.TargetLocationFormat(targetLocationIncomplete)
|
||||
targetLocationComplete := core.TargetLocationFormat(targetLocationIncomplete)
|
||||
err := os.Mkdir(targetLocationComplete, 0700)
|
||||
if err != nil {
|
||||
if os.IsExist(err) {
|
||||
fmt.Println(backend.AnsiError + "Directory already exists" + backend.AnsiReset)
|
||||
fmt.Println(core.AnsiError + "Directory already exists" + core.AnsiReset)
|
||||
os.Exit(1)
|
||||
} else {
|
||||
fmt.Println(backend.AnsiError + "Failed to create directory: " + err.Error() + backend.AnsiReset)
|
||||
fmt.Println(core.AnsiError + "Failed to create directory: " + err.Error() + core.AnsiReset)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user