added support for making symlinks
the assumption here is that every file in the ~/Documents/saves directory should exist as a symlink into ~/Library/Application Support/.
This commit is contained in:
parent
f90e033b71
commit
92debfd3a3
40
main.go
40
main.go
@ -1,16 +1,22 @@
|
||||
// command sk pushes and pulls save files from my server
|
||||
// command saves pushes and pulls save files from my server
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"os/user"
|
||||
)
|
||||
|
||||
const usage = "sk <push|pull>"
|
||||
const usage = "saves <push|pull|link>"
|
||||
|
||||
type link struct {
|
||||
src string
|
||||
dst string
|
||||
}
|
||||
|
||||
func main() {
|
||||
u, err := user.Current()
|
||||
@ -19,6 +25,8 @@ func main() {
|
||||
os.Exit(1)
|
||||
}
|
||||
docs := fmt.Sprintf("%s/Documents/", u.HomeDir)
|
||||
saves := fmt.Sprintf("%s/Documents/saves", u.HomeDir)
|
||||
appSupport := fmt.Sprintf("%s/Library/Application Support", u.HomeDir)
|
||||
if len(os.Args) != 2 {
|
||||
fmt.Fprintf(os.Stderr, "%s\n", usage)
|
||||
os.Exit(1)
|
||||
@ -27,14 +35,38 @@ func main() {
|
||||
var cmd *exec.Cmd
|
||||
switch os.Args[1] {
|
||||
case "pull":
|
||||
cmd = exec.Command("rsync", "-auv", "sj.mcquay.me:~/docs/ycg", docs)
|
||||
cmd = exec.Command("rsync", "-auv", "sj.mcquay.me:~/docs/saves", docs)
|
||||
case "push":
|
||||
cmd = exec.Command("rsync", "-auv", fmt.Sprintf("%sycg", docs), "sj.mcquay.me:~/docs/")
|
||||
cmd = exec.Command("rsync", "-auv", fmt.Sprintf("%ssaves", docs), "sj.mcquay.me:~/docs/")
|
||||
case "link":
|
||||
dirs, err := ioutil.ReadDir(saves)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "could not read saves dir: %+v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
for _, dir := range dirs {
|
||||
src := fmt.Sprintf("%s/%s", saves, dir.Name())
|
||||
dst := fmt.Sprintf("%s/%s", appSupport, dir.Name())
|
||||
if err := os.RemoveAll(dst); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "could not make way for link:%+v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
if err := os.Symlink(src, dst); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "could not link:%+v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
return
|
||||
default:
|
||||
fmt.Fprintf(os.Stderr, "%s\n", usage)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if cmd == nil {
|
||||
fmt.Fprintf(os.Stderr, "failed to populate command\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
var so, se bytes.Buffer
|
||||
cmd.Stdout = &so
|
||||
cmd.Stderr = &se
|
||||
|
Loading…
Reference in New Issue
Block a user