-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add folder diff command for comparing with 0gStorage
- Loading branch information
Showing
3 changed files
with
134 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/0glabs/0g-storage-client/transfer" | ||
"github.com/0glabs/0g-storage-client/transfer/dir" | ||
"github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
diffDirArgs downloadArgument | ||
|
||
diffDirCmd = &cobra.Command{ | ||
Use: "diff-dir", | ||
Short: "Diff directory from ZeroGStorage network", | ||
Run: diffDir, | ||
} | ||
) | ||
|
||
func init() { | ||
bindDownloadFlags(diffDirCmd, &diffDirArgs) | ||
|
||
rootCmd.AddCommand(diffDirCmd) | ||
} | ||
|
||
func diffDir(*cobra.Command, []string) { | ||
ctx := context.Background() | ||
var cancel context.CancelFunc | ||
if diffDirArgs.timeout > 0 { | ||
ctx, cancel = context.WithTimeout(ctx, diffDirArgs.timeout) | ||
defer cancel() | ||
} | ||
|
||
localRoot, err := dir.BuildFileTree(diffDirArgs.file) | ||
if err != nil { | ||
logrus.WithError(err).Fatal("Failed to build local file tree") | ||
} | ||
|
||
downloader, closer, err := newDownloader(diffDirArgs) | ||
if err != nil { | ||
logrus.WithError(err).Fatal("Failed to initialize downloader") | ||
} | ||
defer closer() | ||
|
||
zgRoot, err := transfer.BuildFileTree(ctx, downloader, diffDirArgs.root, diffDirArgs.proof) | ||
if err != nil { | ||
logrus.WithError(err).Fatal("Failed to build file tree from ZeroGStorage network") | ||
} | ||
|
||
diffRoot, err := dir.Diff(zgRoot, localRoot) | ||
if err != nil { | ||
logrus.WithError(err).Fatal("Failed to diff directory") | ||
} | ||
|
||
// Print the diff result | ||
dir.PrettyPrint(diffRoot) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters