Unzip an archive
When you have an archive to unzip on a target system, you can use the optional unzip
field to declare this action.
Declaration
If you have an archive to unzip, you can use the unzip
field to declare this action. You must, of course, declare a file with the following extensions:
.zip
.tar
.tar.gz
.tar.bz2
.tar.xz
.rar
.7z
And you will specify the destination folder path. Indeed, it is mandatory to unzip the archive into a folder.
- .aiop
- .aml
- archive.zip
- source: archive.zip
destination: dossier/
unzip: True
compatibility:
- ...
To specify the destination folder path, it is mandatory to end with a /
.
By default, the unzip
field is declared as False
and will not unzip the file. Therefore, it is necessary to declare it as True
for the archive to be unzipped.
Ignoring Folders and Files While Unzipping
You can ignore certain files or folders from the archive by replacing the value True
in the unzip
field with a list of strings. This method is inspired by gitignore (you can find patterns here -> Github (opens in a new tab)).
We have an archive with the following content:
- any_file.cpp
- my_file.txt
- file_to_keep.txt
- my_other_file.txt
- my_video.mp4
And the following declaration:
- source: archive.zip
destination: destination_folder/
unzip:
- "*.txt"
- "folder_to_delete/**"
- "!folder_to_delete/file_to_keep.txt"
compatibility:
- ...
In the example above, all files with the .txt
extension and the folder_to_delete/**
folder will be ignored during the extraction. Therefore, they will not appear in the destination_folder
. However, the file folder_to_delete/file_to_keep.txt
will be retained.
The content of the destination_folder
will be:
- any_file.cpp
- file_to_keep.txt
Unzip at package root folder
In case you want to extract all files at the root of the package, here is the syntax:
- source: archive.zip
destination: ./
unzip: true
compatibility:
- ...