Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Add ability to ignore files if they don't exist #253

Open
linkjay opened this issue Apr 23, 2020 · 1 comment
Open

[FEATURE] Add ability to ignore files if they don't exist #253

linkjay opened this issue Apr 23, 2020 · 1 comment
Labels
Enhancement new feature or improvement

Comments

@linkjay
Copy link

linkjay commented Apr 23, 2020

What / Why

Would be nice if there was a way to specify in the tar options to ignore files if they don't exist.

In my code, I am specifying a list of files that I want to compress into an archive, but it's in a dynamic directory so sometimes the files get removed. This will spit out an error with lstat saying that it does not exist.

When

Simply have an argument in the options table for tar.c

How

Could probably do it and have it almost like a "less strict" mode. When the file is being retrieved for the archive, have a checker that is like if(!fs.existsSync(file)) { return } or something.

Current Behavior

Feeding in a list of files in an array, and having one of them not exist will pass an error.

Expected Behavior

Having an option to specify something like ignoreNotFound should have it just ignore any entries in the array that do not exist.

@isaacs
Copy link
Owner

isaacs commented Aug 10, 2021

This is a completely reasonable idea, I think.

The inverse of this, I notice that tar.x({file}, ['not-found-in-archive']) does not warn that the file wasn't found in the archive, and tar xf file.tar not-found does warn, so that's another issue. (The reason is that the files list is converted into a filter function, but there's no check to see that every file listed was actually found.)

Maybe a decent way forward is to implement ignoreMissing: Boolean option, which defaults to true for extraction/parsing (and will warn if not ignored), and false for creation. Then in a semver major bump (ie, tar v7), we can make it default to true for both, but make it a warning rather than error if the file is missing, to match bsdtar? (Note that warnings are errors in strict: true mode, so anyone who still wants the crash can have it.)

@darcyclarke darcyclarke added the Enhancement new feature or improvement label Jul 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement new feature or improvement
Projects
None yet
Development

No branches or pull requests

3 participants