File tree 3 files changed +35
-2
lines changed
3 files changed +35
-2
lines changed Original file line number Diff line number Diff line change @@ -261,6 +261,18 @@ func RestoreShelf(cliCtx *cli.Context) error {
261
261
return err
262
262
}
263
263
264
+ // If the symlink path in db is absolute, it will be put in home directory
265
+ if ! path .IsAbs (lPath ) {
266
+ fmt .Printf ("lPath is abs: " )
267
+ home := getHomeDir ()
268
+ lPath = path .Join (home , lPath )
269
+ }
270
+
271
+ err = os .MkdirAll (path .Dir (lPath ), 0755 )
272
+ if err != nil {
273
+ return err
274
+ }
275
+
264
276
err = os .Symlink (path .Join (shelfPath , fName ), lPath )
265
277
if err != nil {
266
278
if os .IsExist (err ) {
Original file line number Diff line number Diff line change @@ -2,9 +2,11 @@ package main
2
2
3
3
import (
4
4
"encoding/json"
5
+ "fmt"
5
6
"io"
6
7
"os"
7
8
"path"
9
+ "strings"
8
10
)
9
11
10
12
// DB is the db for shelf to store where each symlink is supposed to go.
@@ -27,7 +29,21 @@ func (db *DB) Marshal(w io.Writer) error {
27
29
28
30
// AddLink adds the file and link paths to the DB
29
31
func (db * DB ) AddLink (filePath , linkPath string ) {
30
- db .Links [filePath ] = linkPath
32
+ // If the linkpath is in the home directory, only put absolute path from home
33
+ home := getHomeDir ()
34
+ if strings .HasPrefix (linkPath , home ) {
35
+
36
+ // Strip home directory
37
+ l := strings .TrimPrefix (linkPath , home )
38
+
39
+ // Strip any extra slashes at the prefix
40
+ l = strings .TrimPrefix (l , "/" )
41
+
42
+ fmt .Printf ("linkpath: %s, home: %s\n " , linkPath , home )
43
+ db .Links [filePath ] = path .Clean (l )
44
+ return
45
+ }
46
+ db .Links [filePath ] = path .Clean (linkPath )
31
47
}
32
48
33
49
// NewDB creates a shelf DB
Original file line number Diff line number Diff line change @@ -38,6 +38,10 @@ func GetOrCreateShelvesDir() (string, error) {
38
38
}
39
39
40
40
func getShelfDirPath () string {
41
+ return path .Join (getHomeDir (), shelvesDIR )
42
+ }
43
+
44
+ func getHomeDir () string {
41
45
var (
42
46
home string
43
47
)
@@ -47,7 +51,8 @@ func getShelfDirPath() string {
47
51
home = os .Getenv ("HOME" )
48
52
}
49
53
}
50
- return path .Join (home , shelvesDIR )
54
+
55
+ return path .Clean (home )
51
56
}
52
57
53
58
// SOURCE: https://gist.github.com/mimoo/25fc9716e0f1353791f5908f94d6e726
You can’t perform that action at this time.
0 commit comments