11package main
22
33import (
4- "github.com/j-keck/zfs-snap-diff/pkg/zfs"
4+ "errors"
5+ "flag"
6+ "fmt"
7+ "github.com/j-keck/plog"
8+ "github.com/j-keck/zfs-snap-diff/pkg/config"
59 "github.com/j-keck/zfs-snap-diff/pkg/diff"
10+ "github.com/j-keck/zfs-snap-diff/pkg/fs"
611 "github.com/j-keck/zfs-snap-diff/pkg/scanner"
7- "github.com/j-keck/plog"
12+ "github.com/j-keck/zfs-snap-diff/pkg/zfs"
13+ "math"
814 "os"
915 "path/filepath"
10- "fmt"
11- "time"
12- "flag"
13- "math"
14- "strings"
1516 "strconv"
16- "errors"
17- "github.com/j-keck/zfs-snap-diff/pkg/config"
18- "github.com/j-keck/zfs-snap-diff/pkg/fs"
17+ "strings"
18+ "time"
1919)
2020
2121var version string = "SNAPSHOT"
@@ -34,14 +34,13 @@ func main() {
3434 flag .PrintDefaults ()
3535 fmt .Fprintf (os .Stderr , "\n ACTIONS:\n " )
3636 fmt .Fprintf (os .Stderr , " list : list zfs snapshots where the given file was modified\n " )
37- fmt .Fprintf (os .Stderr , " cat <#|SNAPSHOT>: show the file content from the given snapshot\n " );
37+ fmt .Fprintf (os .Stderr , " cat <#|SNAPSHOT>: show the file content from the given snapshot\n " )
3838 fmt .Fprintf (os .Stderr , " diff <#|SNAPSHOT>: show a diff from the selected snapshot to the actual version\n " )
3939 fmt .Fprintf (os .Stderr , " restore <#|SNAPSHOT>: restore the file from the given snapshot\n " )
4040 fmt .Fprintf (os .Stderr , "\n You can use the snapshot number from the `list` output or the snapshot name to select a snapshot.\n " )
4141 fmt .Fprintf (os .Stderr , "\n Project home page: https://j-keck.github.io/zfs-snap-diff\n " )
4242 }
4343
44-
4544 initLogger ()
4645 cliCfg := parseFlags ()
4746 log := reconfigureLogger (cliCfg )
@@ -56,7 +55,6 @@ func main() {
5655 return
5756 }
5857
59-
6058 // file path
6159 fileName := flag .Arg (0 )
6260 filePath , err := filepath .Abs (fileName )
@@ -66,7 +64,6 @@ func main() {
6664 }
6765 log .Debugf ("full path: %s" , filePath )
6866
69-
7067 // init zfs handler
7168 zfs , ds , err := zfs .NewZFSForFilePath (filePath )
7269 if err != nil {
@@ -75,8 +72,7 @@ func main() {
7572 }
7673 log .Debugf ("work on dataset: %s" , ds .Name )
7774
78-
79- // action
75+ // action
8076 action := flag .Arg (1 )
8177 switch action {
8278 case "list" :
@@ -120,7 +116,7 @@ func main() {
120116 }
121117
122118 file , err := fs .GetFileHandle (version .Backup .Path )
123- if err != nil {
119+ if err != nil {
124120 log .Errorf ("unable to find file in the snapshot - %v" , err )
125121 return
126122 }
@@ -168,7 +164,6 @@ func main() {
168164 return
169165 }
170166
171-
172167 backupPath , err := version .Actual .Backup ()
173168 if err != nil {
174169 log .Errorf ("unable to backup the acutal version - %v" , err )
@@ -186,7 +181,6 @@ func main() {
186181 }
187182}
188183
189-
190184func lookupRequestedVersion (filePath , versionName string ) (* scanner.FileVersion , error ) {
191185
192186 // load file-versions from cache file
@@ -195,7 +189,6 @@ func lookupRequestedVersion(filePath, versionName string) (*scanner.FileVersion,
195189 return nil , err
196190 }
197191
198-
199192 // `versionName` can be the snapshot number from the `list` output or the name
200193 var version * scanner.FileVersion
201194 if idx , err := strconv .Atoi (versionName ); err == nil {
@@ -223,7 +216,6 @@ func lookupRequestedVersion(filePath, versionName string) (*scanner.FileVersion,
223216 }
224217}
225218
226-
227219func humanDuration (dur time.Duration ) string {
228220 s := int (dur .Seconds ())
229221 if s < 60 {
0 commit comments