forked from fiam/macapptool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathactions.go
47 lines (42 loc) · 781 Bytes
/
actions.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"fmt"
"os"
"path/filepath"
)
func osRemove(path string) error {
if *dryRun {
fmt.Printf("rm %s\n", path)
return nil
}
return os.Remove(path)
}
func osRename(source, dest string) error {
if *dryRun {
fmt.Printf("mv %s %s\n", source, dest)
return nil
}
return os.Rename(source, dest)
}
func symlink(source, dest string) error {
if *dryRun {
fmt.Printf("ln -s %s %s\n", dest, source)
return nil
}
symRel, err := filepath.Rel(filepath.Dir(source), dest)
if err != nil {
return err
}
cwd, err := os.Getwd()
if err != nil {
return err
}
if err := os.Chdir(filepath.Dir(source)); err != nil {
return err
}
defer os.Chdir(cwd)
if err := os.Symlink(symRel, filepath.Base(symRel)); err != nil {
return err
}
return nil
}