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

.glob() with options.cwd is not working at 5.x #455

Closed
hyoo opened this issue Sep 22, 2020 · 8 comments
Closed

.glob() with options.cwd is not working at 5.x #455

hyoo opened this issue Sep 22, 2020 · 8 comments

Comments

@hyoo
Copy link

hyoo commented Sep 22, 2020

Just found the source problem, in the pr

#433

The non-backward compatibility needs to be documented or clearly communicated to the users !!!

Is there any workaround that can avoid including absolute path?

@ctalkington
Copy link
Member

This was communicated in the changes for 5.0. Its also why it was released as a new major version per semver.

please provide an example of your usage

@simpixelated
Copy link

simpixelated commented Jan 5, 2021

I ran into the same problem, found the breaking change note in the changelog, and updated my usage:

-archive.glob('../frontend/build/static/js/main.*.js', null, { name: 'ghost-inspector.js', prefix });
+archive.glob('main.*.js', { cwd: '../frontend/build/static/js/'}, { name: 'ghost-inspector.js', prefix });

However the problem I'm having now is that it doesn't seem to be using options.name anymore. The final archive is using the original filenames it found via glob.

EDIT: it appears in the previous version, it only overwrote the entrydata name if options.cwd was set. In version 5.x, it always overwrites the name: https://github.com/archiverjs/node-archiver/pull/433/files#diff-826e5ed9069c92baa50ec46dde8074a6789b4c90837c5ede0e6b0438e3c34309L734-L737

@ctalkington
Copy link
Member

@simpixelated can you provide sn example of file names inside archive and expected names?

@simpixelated
Copy link

@ctalkington

filename inside the archive (matches original filename):

main.7f7102c9.js

expected (with {name: 'ghost-inspector.js'}:

ghost-inspector.js

@hyoo
Copy link
Author

hyoo commented Jan 11, 2021

Here is my use-case. I have files in /a/b/c1/fileN/ and /a/b/c2/filesN for example, and I want to build archive files based on the level of C, keeping the sub-directory structures. So, when user downloaded and unzipped, it shows like c1/filesN and c2/filesN.

@ctalkington
Copy link
Member

@hyoo you should be able to do that with:

archive.directory('a/b/c1', 'c1')

@grantholle
Copy link

I feel like an idiot but I can't seem to get glob working. I have an array of paths that I want. I'm confused by cwd and to what it refers. I'm using 5.3.0

const output = fs.createWriteStream('output.zip')

const allowedItems = [
  'file.xml',
  'directory1',
  'directory2',
]

archiver.pipe(output)
archiver.directory('/a/directory/path', false)

for (const path of allowedItems) {
  archiver.glob(path, { cwd: '????' })
}

archiver.finalize()

Is it the relative path of the real file path or what it will be in the zip? Thanks!

@ctalkington
Copy link
Member

cwd stands for current working directory and tells glob where it should base its search. the glob pattern should be relative to cwd

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

No branches or pull requests

4 participants