diff options
Diffstat (limited to 'cmd')
| -rw-r--r-- | cmd/cat.go | 54 | ||||
| -rw-r--r-- | cmd/list.go | 20 | 
2 files changed, 66 insertions, 8 deletions
@@ -3,19 +3,63 @@ package cmd  import (  	"fmt"  	"golang.flu0r1ne.net/zfdiff/snap" +	"os" +	"io"  )  func Cat(params []string) { -	if(len(params) == 0) { +	n_params := len(params) + +	if(n_params == 0) {  		die.Fatal("Reference file is required")  	} -	if(len(params) > 3) { +	if(n_params > 3) {  		die.Fatal("Too many arguments provided")  	} -	snapRef := snap.ToRelative(params[0]) -	reference := params[1] +	var reference string +	snapish := "" + +	if(n_params == 1) { +		reference = params[0] +	} else { +		snapish, reference = params[0], params[1] +	} + +	snapRef := snap.ToRelative(snapish) + +	oracle := snap.GetOracle(reference) + +	path := oracle.ResolveRelative(snapRef) + +	file, err := os.Open(path) + +	if err != nil { +		die.Fatal("Could not open snapshot %s\nError: %v", path, err) +	} + +	defer func() { +        if err = file.Close(); err != nil { +            die.Fatal("Could not close file %s\nError: %v", path, err) +        } +    }() + +	buf := make([]byte, 10*1024*1024) //10Ki + +    for { +        n, err := file.Read(buf) + +        if n > 0 { +            fmt.Printf("%s", buf[:n]) +        } + +        if err == io.EOF { +            break +        } -	fmt.Println(snapRef, reference); +        if err != nil { +            die.Fatal("Encountered error while reading file: %v", err) +        } +    }  }
\ No newline at end of file diff --git a/cmd/list.go b/cmd/list.go index 99d5f24..5849975 100644 --- a/cmd/list.go +++ b/cmd/list.go @@ -3,13 +3,14 @@ package cmd  import (  	"fmt"  	"flag" +	"golang.flu0r1ne.net/zfdiff/snap"  )  func List(params []string) {  	flags := flag.NewFlagSet("list", flag.ExitOnError)  	var withPaths bool - +	  	withName := aliasedBoolVar(  		flags,  		&withPaths, @@ -32,6 +33,19 @@ func List(params []string) {  	reference := flags.Arg(0) -	fmt.Printf(reference) -	fmt.Printf("Your flag is: %t", withPaths); +	snaps := snap.GetTimeseries(reference) + +	for _, s := range snaps { +		if s.Reference == "" { +			continue +		} + +		fmt.Printf("%s", s.Name) + +		if withPaths { +			fmt.Printf(", %s", s.Reference) +		} + +		fmt.Println("") +	}  }  | 
