Skip to content

Commit 9e0da7c

Browse files
author
jieggii
committed
Add existancy check when running extract
If target does not exist, diff compares target being extracted to `/dev/null`
1 parent 5b686cf commit 9e0da7c

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

internal/commands/extract.go

+13
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,23 @@ func Extract(ctx *cli.Context) error {
112112
output.Stdout.Printf(outputString)
113113

114114
if !nodiff { // if --no-diff flag is not used
115+
115116
outputStringLen := len(outputString)
116117
outputDivider := strings.Repeat("-", outputStringLen)
117118

118119
output.Stdout.Println(strings.Repeat(" ", int(outputStringLen/2)-4), "diff(s):")
120+
121+
targetExists, err := fs.NodeExists(target)
122+
if err != nil {
123+
output.Warning.Printf("could not check if %v exists (%v)", target, err)
124+
targetExists = true
125+
}
126+
if !targetExists {
127+
output.Warning.Printf("%v does not exist", target)
128+
target = "/dev/null" // diff will compare node being extracted
129+
// to /dev/null in case if target does not exist
130+
}
131+
119132
output.Stdout.Println(outputDivider)
120133

121134
diffOutput, err := diff.GetDiff(diffBinPath, target, destination)

0 commit comments

Comments
 (0)