Skip to content

Commit

Permalink
overwrite by default (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
shizhMSFT authored Jan 10, 2019
1 parent 4cf1be7 commit 05d0b39
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
6 changes: 3 additions & 3 deletions cmd/oras/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type pullOptions struct {
targetRef string
allowedMediaTypes []string
allowAllMediaTypes bool
overwrite bool
keepOldFiles bool
pathTraversal bool
output string
verbose bool
Expand Down Expand Up @@ -50,7 +50,7 @@ Example - Pull all files, any media type:

cmd.Flags().StringArrayVarP(&opts.allowedMediaTypes, "media-type", "t", nil, "allowed media types to be pulled")
cmd.Flags().BoolVarP(&opts.allowAllMediaTypes, "allow-all", "a", false, "allow all media types to be pulled")
cmd.Flags().BoolVarP(&opts.overwrite, "force", "f", false, "allow overwrite on existing files")
cmd.Flags().BoolVarP(&opts.keepOldFiles, "keep-old-files", "k", false, "do not replace existing files when pulling, treat them as errors")
cmd.Flags().BoolVarP(&opts.pathTraversal, "allow-path-traversal", "T", false, "allow storing files out of the output directory")
cmd.Flags().StringVarP(&opts.output, "output", "o", "", "output directory")
cmd.Flags().BoolVarP(&opts.verbose, "verbose", "v", false, "verbose output")
Expand All @@ -73,7 +73,7 @@ func runPull(opts pullOptions) error {

resolver := newResolver(opts.username, opts.password)
store := content.NewFileStore(opts.output)
store.AllowOverwrite = opts.overwrite
store.DisableOverwrite = opts.keepOldFiles
store.AllowPathTraversalOnWrite = opts.pathTraversal
files, err := oras.Pull(context.Background(), resolver, opts.targetRef, store, opts.allowedMediaTypes...)
if err != nil {
Expand Down
1 change: 0 additions & 1 deletion pkg/content/content_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ func (suite *ContentTestSuite) SetupSuite() {
err := ioutil.WriteFile(testFileName, testContent, 0644)
suite.Nil(err, "no error creating test file on disk")
testFileStore := NewFileStore(testDirRoot)
testFileStore.AllowOverwrite = true
_, err = testFileStore.Add(testRef, "", testFileName)
suite.Nil(err, "no error adding item to file store")
suite.TestFileStore = testFileStore
Expand Down
4 changes: 2 additions & 2 deletions pkg/content/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var (

// FileStore provides content from the file system
type FileStore struct {
AllowOverwrite bool
DisableOverwrite bool
AllowPathTraversalOnWrite bool

root string
Expand Down Expand Up @@ -130,7 +130,7 @@ func (s *FileStore) Writer(ctx context.Context, opts ...content.WriterOpt) (cont
return nil, ErrPathTraversalDisallowed
}
}
if !s.AllowOverwrite {
if s.DisableOverwrite {
if _, err := os.Stat(path); err == nil {
return nil, ErrOverwriteDisallowed
} else if !os.IsNotExist(err) {
Expand Down

0 comments on commit 05d0b39

Please sign in to comment.