Skip to content

Conversation

@hannahhoward
Copy link
Member

fix #174

if output file exists in source path, just overwrite it, but don't include it in the packed car file

requires storacha/files-from-path#46

fix #174

if output file exists in source path, just overwrite it, but don't
include it in the packed car file
Copy link

@autonome autonome left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, thanks! added a couple of minor non-blocking suggestions

Comment on lines +27 to +30
let fullOutputPath
if (opts.output) {
fullOutputPath = path.resolve(opts.output)
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let fullOutputPath
if (opts.output) {
fullOutputPath = path.resolve(opts.output)
}
const fullOutputPath = opts.output !== null ? path.resolve(opts.output) : null;
  • stricter check
  • remove unnecessary modifiableness

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not convinced this will work. It's worth checking but I don't think opts.output is ever null. It might be undefined or the empty string.

? await filesFromPaths(paths, {
hidden,
filter: (filePath) => {
const include = !fullOutputPath || filePath !== fullOutputPath

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const include = !fullOutputPath || filePath !== fullOutputPath
const include = fullOutputPath !== null || filePath !== fullOutputPath
  • stricter check

Copy link
Member

@alanshaw alanshaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have super strong opinions here but I think I'd prefer an error. If I output to a CAR file in the source directory that I wanted to keep, then that CAR is now not in the new CAR and is no longer in the source directory (it got overwritten). It is lost forever.

@autonome
Copy link

I don't have super strong opinions here but I think I'd prefer an error. If I output to a CAR file in the source directory that I wanted to keep, then that CAR is now not in the new CAR and is no longer in the source directory (it got overwritten). It is lost forever.

agree that it's better to bail than to make an assumption that results in permanent data loss.

however, the caller has themselves pointed to the output file. if they wanted to keep that file, why would they have made it the output file?

@alanshaw
Copy link
Member

People make mistakes!

@autonome
Copy link

People make mistakes!

ok first do no harm then, bail loudly ftw

low priority would be a --force or --overwrite for the not-a-mistake case

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

when output file exists, something terrible happens

4 participants