Skip to content

Commit aa1ea15

Browse files
fix(sync): fix dry-run failing consecutive runs by creating directories in target dir
Signed-off-by: Jonas Switala <[email protected]>
1 parent a3070ea commit aa1ea15

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

cmd/skopeo/sync.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ func parseRepositoryReference(input string) (reference.Named, error) {
166166
// destinationReference creates an image reference using the provided transport.
167167
// It returns a image reference to be used as destination of an image copy and
168168
// any error encountered.
169-
func destinationReference(destination string, transport string) (types.ImageReference, error) {
169+
func destinationReference(destination string, transport string, dryRun bool) (types.ImageReference, error) {
170170
var imageTransport types.ImageTransport
171171

172172
switch transport {
@@ -181,9 +181,11 @@ func destinationReference(destination string, transport string) (types.ImageRefe
181181
if !os.IsNotExist(err) {
182182
return nil, fmt.Errorf("Destination directory could not be used: %w", err)
183183
}
184-
// the directory holding the image must be created here
185-
if err = os.MkdirAll(destination, 0755); err != nil {
186-
return nil, fmt.Errorf("Error creating directory for image %s: %w", destination, err)
184+
if !dryRun {
185+
// the directory holding the image must be created here
186+
if err = os.MkdirAll(destination, 0755); err != nil {
187+
return nil, fmt.Errorf("Error creating directory for image %s: %w", destination, err)
188+
}
187189
}
188190
imageTransport = directory.Transport
189191
default:
@@ -697,7 +699,7 @@ func (opts *syncOptions) run(args []string, stdout io.Writer) (retErr error) {
697699
destSuffix = path.Base(destSuffix)
698700
}
699701

700-
destRef, err := destinationReference(path.Join(destination, destSuffix)+opts.appendSuffix, opts.destination)
702+
destRef, err := destinationReference(path.Join(destination, destSuffix)+opts.appendSuffix, opts.destination, opts.dryRun)
701703
if err != nil {
702704
return err
703705
}

0 commit comments

Comments
 (0)