$(which zip) -r ../data.zip .
The contents of the folders are changing dynamically overtime, I tested it first with including
huge.pdf file and later deleted it, but still
data.zip stays the same size. On unzipping I could see the
huge.pdf file there.
I wish that zip command overrides the existing archive completely.
and I'm executing this shell command in an application (nodejs)
Edit: I don't think so the linked question is duplicate.
First note that executing
$(which zip) is the same as executing it as just
which utility locates a program file in the user's path.
Given an existing Zip archive,
zip will add new files, replace existing files, but it will not delete files in the archive if those files have been removed from the file system.
To delete a file from a Zip archive:
$ zip -d archive.zip filename
You may obviously also just remove the archive with
rm before re-creating it.
For your NodeJS script, you could use
rm -f ../data.zip && zip -r ../data.zip .
-f flag to
rm not fail if the archive does not exist.
As it states the
zip command's help entry:
The default action is to add or replace zipfile entries from list
This explains why the default behavior does not involve deleting files in the zipfile, and the reason why
huge.pdf remains in it.
If you want to override the existing archive completely, you could create a new temporary zipfile and then replace the previous one. Also, the
which command invocation does not appear to be necessary, so the command should be the following:
zip -r temp.zip . ; mv temp.zip ../data.zip