Skip to content
This repository was archived by the owner on Aug 3, 2024. It is now read-only.

Commit cecf605

Browse files
authored
fix(triggers/bernard): do not retrieve path for roots (#33)
1 parent eb45791 commit cecf605

5 files changed

Lines changed: 21 additions & 16 deletions

File tree

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require (
88
github.com/justinas/alice v1.2.0
99
github.com/kirsle/configdir v0.0.0-20170128060238-e45d2f54772f
1010
github.com/m-rots/bernard v0.3.3-0.20200804121414-38394a889536
11-
github.com/m-rots/stubbs v1.0.1-0.20200804111142-55ef5d1857d9
11+
github.com/m-rots/stubbs v1.1.0
1212
github.com/mattn/go-sqlite3 v2.0.3+incompatible
1313
github.com/natefinch/lumberjack v2.0.0+incompatible
1414
github.com/pkg/errors v0.9.1 // indirect

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ github.com/m-rots/bernard v0.3.3-0.20200804121414-38394a889536 h1:0aY4VrX9R+Y0VA
1414
github.com/m-rots/bernard v0.3.3-0.20200804121414-38394a889536/go.mod h1:yDQffALXQDh6sTXdFCbI2rJtYuXgx41MyJM6Sf/j7Sc=
1515
github.com/m-rots/stubbs v1.0.0 h1:lBrjn27J32/iGHp7eKPYGcphuqDIg5UIs/YI4q1m63Q=
1616
github.com/m-rots/stubbs v1.0.0/go.mod h1:iDS6z2oonw2UMo2l0S1WTPJ9git7FWU4YEo6fq7F2WU=
17-
github.com/m-rots/stubbs v1.0.1-0.20200804111142-55ef5d1857d9 h1:ent/Dhpzz7hiCBiDgJL2iS5G0Yzd/a9GpP6XSOet0Qc=
18-
github.com/m-rots/stubbs v1.0.1-0.20200804111142-55ef5d1857d9/go.mod h1:Ive+DY/P1EikQ644M3tuyvsO/7ohPLnmEru2L+6hbVw=
17+
github.com/m-rots/stubbs v1.1.0 h1:QR1LHxFYPasju/sEO0KLmI5/RADF70CW3ZtisCs7XrQ=
18+
github.com/m-rots/stubbs v1.1.0/go.mod h1:Ive+DY/P1EikQ644M3tuyvsO/7ohPLnmEru2L+6hbVw=
1919
github.com/mattn/go-sqlite3 v2.0.3+incompatible h1:gXHsfypPkaMZrKbD5209QV9jbUTJKjyR5WD3HYQSd+U=
2020
github.com/mattn/go-sqlite3 v2.0.3+incompatible/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
2121
github.com/natefinch/lumberjack v2.0.0+incompatible h1:4QJd3OLAMgj7ph+yZTuX13Ld4UpgHp07nNdFX7mqFfM=

triggers/bernard/bernard.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func New(c Config) (autoscan.Trigger, error) {
4444
Logger()
4545

4646
const scope = "https://www.googleapis.com/auth/drive.readonly"
47-
auth, err := stubbs.FromFile(c.AccountPath, []string{scope}, 3600)
47+
auth, err := stubbs.FromFile(c.AccountPath, []string{scope})
4848
if err != nil {
4949
return nil, fmt.Errorf("%v: %w", err, autoscan.ErrFatal)
5050
}

triggers/bernard/paths.go

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func NewPathsHook(driveID string, store *bds, diff *sqlite.Difference) (bernard.
2525
for _, f := range diff.AddedFiles {
2626
p, err := getFolderPath(store, driveID, f.Parent, folderMaps.Current)
2727
if err != nil {
28-
return fmt.Errorf("failed building file path for added file %v: %w", f.ID, err)
28+
return fmt.Errorf("building file path for added file %v: %w", f.ID, err)
2929
}
3030

3131
paths.AddedFiles = append(paths.AddedFiles, filepath.Join(p, f.Name))
@@ -36,7 +36,7 @@ func NewPathsHook(driveID string, store *bds, diff *sqlite.Difference) (bernard.
3636
// new path
3737
p, err := getFolderPath(store, driveID, f.New.Parent, folderMaps.Current)
3838
if err != nil {
39-
return fmt.Errorf("failed building file path for changed file %v: %w", f.New.ID, err)
39+
return fmt.Errorf("building file path for changed file %v: %w", f.New.ID, err)
4040
}
4141

4242
paths.ChangedFiles = append(paths.ChangedFiles, filepath.Join(p, f.New.Name))
@@ -45,7 +45,7 @@ func NewPathsHook(driveID string, store *bds, diff *sqlite.Difference) (bernard.
4545
if !f.Old.Trashed && f.Old.ID != "" {
4646
p, err := getFolderPath(store, driveID, f.Old.Parent, folderMaps.Old)
4747
if err != nil {
48-
return fmt.Errorf("failed building removed file path for changed file %v: %w", f.Old.ID, err)
48+
return fmt.Errorf("building removed file path for changed file %v: %w", f.Old.ID, err)
4949
}
5050

5151
paths.RemovedFiles = append(paths.RemovedFiles, filepath.Join(p, f.Old.Name))
@@ -56,7 +56,7 @@ func NewPathsHook(driveID string, store *bds, diff *sqlite.Difference) (bernard.
5656
for _, f := range diff.RemovedFiles {
5757
p, err := getFolderPath(store, driveID, f.Parent, folderMaps.Old)
5858
if err != nil {
59-
return fmt.Errorf("failed building file path for removed file %v: %w", f.ID, err)
59+
return fmt.Errorf("building file path for removed file %v: %w", f.ID, err)
6060
}
6161

6262
paths.RemovedFiles = append(paths.RemovedFiles, filepath.Join(p, f.Name))
@@ -68,14 +68,14 @@ func NewPathsHook(driveID string, store *bds, diff *sqlite.Difference) (bernard.
6868
// get changed file paths (descendants of newRoots)
6969
changedNewFiles, err := getChangedFolderFiles(store, driveID, newRoots, folderMaps.Current, fileMaps.Current)
7070
if err != nil {
71-
return fmt.Errorf("failed building changed folder descendant files: %w", err)
71+
return fmt.Errorf("building changed folder descendant files: %w", err)
7272
}
7373

7474
for _, f := range changedNewFiles {
7575
p, err := getFolderPath(store, driveID, f.Parent, folderMaps.Current)
7676
if err != nil {
77-
return fmt.Errorf("failed building changed file path for change folder "+
78-
"descendant file %v: %w", f.ID, err)
77+
return fmt.Errorf("building changed file path for change folder descendant file %v: %w",
78+
f.ID, err)
7979
}
8080

8181
paths.ChangedFiles = append(paths.ChangedFiles, filepath.Join(p, f.Name))
@@ -84,7 +84,7 @@ func NewPathsHook(driveID string, store *bds, diff *sqlite.Difference) (bernard.
8484
// get descendents of changed folders (old paths - removed)
8585
removedOldFiles, err := getChangedFolderFiles(store, driveID, oldRoots, folderMaps.Old, fileMaps.Old)
8686
if err != nil {
87-
return fmt.Errorf("failed building removed folder descendant files: %w", err)
87+
return fmt.Errorf("building removed folder descendant files: %w", err)
8888
}
8989

9090
for _, f := range removedOldFiles {
@@ -94,8 +94,8 @@ func NewPathsHook(driveID string, store *bds, diff *sqlite.Difference) (bernard.
9494

9595
p, err := getFolderPath(store, driveID, f.Parent, folderMaps.Old)
9696
if err != nil {
97-
return fmt.Errorf("failed building removed file path for change folder "+
98-
"descendant file %v: %w", f.ID, err)
97+
return fmt.Errorf("building removed file path for change folder descendant file %v: %w",
98+
f.ID, err)
9999
}
100100

101101
paths.RemovedFiles = append(paths.RemovedFiles, filepath.Join(p, f.Name))
@@ -209,6 +209,11 @@ func getDiffFolderMaps(diff *sqlite.Difference) *diffFolderMaps {
209209
func getFolderPath(store *bds, driveId string, folderId string, folderMap map[string]datastore.Folder) (string, error) {
210210
path := ""
211211

212+
// folderId == driveId
213+
if folderId == driveId {
214+
return path, nil
215+
}
216+
212217
// get top folder
213218
topFolder, ok := folderMap[folderId]
214219
if !ok {

triggers/bernard/postprocess.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func NewPostProcessBernardDiff(driveID string, store *bds, diff *sqlite.Differen
1515

1616
ef, err := store.GetFile(driveID, df.ID)
1717
if err != nil {
18-
return fmt.Errorf("failed retrieving file (id: %v): %w", df.ID, err)
18+
return fmt.Errorf("retrieving file (id: %v): %w", df.ID, err)
1919
}
2020

2121
switch {
@@ -32,7 +32,7 @@ func NewPostProcessBernardDiff(driveID string, store *bds, diff *sqlite.Differen
3232

3333
ef, err := store.GetFolder(driveID, df.ID)
3434
if err != nil {
35-
return fmt.Errorf("failed retrieving folder (id: %v): %w", df.ID, err)
35+
return fmt.Errorf("retrieving folder (id: %v): %w", df.ID, err)
3636
}
3737

3838
switch {

0 commit comments

Comments
 (0)