mirror of
https://github.com/rwinkhart/libmutton.git
synced 2026-09-03 15:47:27 -04:00
When a folder is created on the client, also create it on the server
This commit is contained in:
@@ -1,23 +0,0 @@
|
|||||||
package backend
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
)
|
|
||||||
|
|
||||||
// AddFolder creates a new directory at targetLocation
|
|
||||||
func AddFolder(targetLocation string) {
|
|
||||||
// create the directory specified by targetLocation
|
|
||||||
err := os.Mkdir(targetLocation, 0700)
|
|
||||||
if err != nil {
|
|
||||||
if os.IsExist(err) {
|
|
||||||
fmt.Println(AnsiError + "Directory already exists" + AnsiReset)
|
|
||||||
os.Exit(1)
|
|
||||||
} else {
|
|
||||||
fmt.Println(AnsiError + "Failed to create directory: " + err.Error() + AnsiReset)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// TODO If in online mode, create the directory on the server
|
|
||||||
os.Exit(0)
|
|
||||||
}
|
|
||||||
+24
-1
@@ -90,7 +90,7 @@ func Shear(targetLocationIncomplete string, deviceID string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else { // if running on the client... (online mode determined dynamically in GetSSHOutput, will simply exit if not in online mode)
|
} else { // if running on the client... (online mode determined dynamically in GetSSHOutput, will silently exit if not in online mode)
|
||||||
// determine client device ID (to send to server, avoids creating a deletion file for the client device)
|
// determine client device ID (to send to server, avoids creating a deletion file for the client device)
|
||||||
deviceID = deviceIDList[0].Name()
|
deviceID = deviceIDList[0].Name()
|
||||||
// below: deviceID and targetLocationIncomplete are separated by \x1d, path separators are replaced with \x1e, and spaces are replaced with \x1f
|
// below: deviceID and targetLocationIncomplete are separated by \x1d, path separators are replaced with \x1e, and spaces are replaced with \x1f
|
||||||
@@ -99,3 +99,26 @@ func Shear(targetLocationIncomplete string, deviceID string) {
|
|||||||
|
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AddFolder creates a new directory at targetLocation
|
||||||
|
// if running on the client, it will also call the server to create the directory
|
||||||
|
func AddFolder(targetLocationIncomplete string, onServer bool) {
|
||||||
|
// get the full targetLocation path and create the target
|
||||||
|
targetLocationComplete := backend.TargetLocationFormat(targetLocationIncomplete[1:])
|
||||||
|
err := os.Mkdir(targetLocationComplete, 0700)
|
||||||
|
if err != nil {
|
||||||
|
if os.IsExist(err) {
|
||||||
|
fmt.Println(backend.AnsiError + "Directory already exists" + backend.AnsiReset)
|
||||||
|
os.Exit(1)
|
||||||
|
} else {
|
||||||
|
fmt.Println(backend.AnsiError + "Failed to create directory: " + err.Error() + backend.AnsiReset)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !onServer { // if running on the client... (online mode determined dynamically in GetSSHOutput, will silently exit if not in online mode)
|
||||||
|
GetSSHOutput("libmuttonserver addfolder "+strings.ReplaceAll(targetLocationIncomplete, " ", "\x1f"), false)
|
||||||
|
}
|
||||||
|
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user