Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dfarrell07/e5898d01fb94b5ded6d1 to your computer and use it in GitHub Desktop.
Save dfarrell07/e5898d01fb94b5ded6d1 to your computer and use it in GitHub Desktop.
Notes on my PR to add the `--strip-components` flag to camptocamp-archive

camptocamp-archive strip-components PR notes

My goal is to give camptocamp-archive access to the --strip-components flag in a backwards-compatible way.

The examples below demonstrate that gini-archive implemented --strip-components in a backwards-incompatible way, while the code proposed in my PR is API backwards compatible with the current camptocamp-archive code and adds access to the --strip-components flag.

Examples

Strip 0 components

Relevant params overridden (everything else irrelevant or default):

target='/opt/'
name='opendaylight-0.2.2'
Current code

Note that this example, --strip-components=0, is equivalent to not including that flag at all. That's what makes it possible to compare to the current code, which doesn't actually support --strip-components.

Yields this extract command:

tar --no-same-owner --no-same-permissions -xzf /usr/src/opendaylight-0.2.2.tar.gz -C /opt/

And this overall command:

mkdir -p /opt/ && tar --no-same-owner --no-same-permissions -xzf /usr/src/opendaylight-0.2.2.tar.gz -C /opt/

When executed:

[/usr/src]$ ls opendaylight-0.2.2.tar.gz
opendaylight-0.2.2.tar.gz
[/usr/src]$ ls /opt
apacheds-2.0.0_M19  google  vagrant
[/usr/src]$ mkdir -p /opt/ && tar --no-same-owner --no-same-permissions -xzf /usr/src/opendaylight-0.2.2.tar.gz -C /opt/
[/usr/src]$ ls /opt
apacheds-2.0.0_M19  distribution-karaf-0.2.2-Helium-SR2  google  vagrant
[/usr/src]$ ls /opt/distribution-karaf-0.2.2-Helium-SR2
bin  configuration  data  deploy  etc  externalapps  lib  system  version.properties
gini-archive code

Yields this extract command:

tar --no-same-owner --no-same-permissions --strip-components=0 -xzf /usr/src/opendaylight-0.2.2.tar.gz -C /opt/opendaylight-0.2.2

And this overall command:

mkdir -p /opt/opendaylight-0.2.2 && tar --no-same-owner --no-same-permissions --strip-components=0 -xzf /usr/src/opendaylight-0.2.2.tar.gz -C /opt/opendaylight-0.2.2

When executed:

[/usr/src]$ ls opendaylight-0.2.2.tar.gz
opendaylight-0.2.2.tar.gz
[/usr/src]$ ls /opt
apacheds-2.0.0_M19  google  vagrant
[/usr/src]$ mkdir -p /opt/opendaylight-0.2.2 && tar --no-same-owner --no-same-permissions --strip-components=0 -xzf /usr/src/opendaylight-0.2.2.tar.gz -C /opt/opendaylight-0.2.2
[/usr/src]$ ls /opt
apacheds-2.0.0_M19  google  opendaylight-0.2.2  vagrant
[/usr/src]$ ls /opt/opendaylight-0.2.2
distribution-karaf-0.2.2-Helium-SR2

Note that this is different from its parent mod - the distribution-karaf-0.2.2-Helium-SR2 directory is inside a opendaylight-0.2.2 directory. The two APIs have diverged and it would take backwards-incompatible changes to reconcile them.

Proposed code

Yields this extract command:

tar --no-same-owner --no-same-permissions --strip-components=0 -xzf /usr/src/opendaylight-0.2.2.tar.gz -C /opt/

And this overall command:

mkdir -p /opt/ && tar --no-same-owner --no-same-permissions --strip-components=0 -xzf /usr/src/opendaylight-0.2.2.tar.gz -C /opt/

When executed:

[/usr/src]$ ls opendaylight-0.2.2.tar.gz
opendaylight-0.2.2.tar.gz
[/usr/src]$ ls /opt
apacheds-2.0.0_M19  google  vagrant
[/usr/src]$ mkdir -p /opt/ && tar --no-same-owner --no-same-permissions --strip-components=0 -xzf /usr/src/opendaylight-0.2.2.tar.gz -C /opt/
[/usr/src]$ ls /opt
apacheds-2.0.0_M19  distribution-karaf-0.2.2-Helium-SR2  google  vagrant
[/usr/src]$ ls /opt/distribution-karaf-0.2.2-Helium-SR2
bin  configuration  data  deploy  etc  externalapps  lib  system  version.properties

The PR's result is the same as the result of the current code. API backwards compatibility is maintained.

Strip 1 component

Relevant params overridden (everything else irrelevant or default):

target='/opt/opendaylight-0.2.2'
name='opendaylight-0.2.2'
strip_components=1
Current code

Can't demonstrate with current code, as it doesn't support --strip-components.

Proposed code

Yields this extract command:

tar --no-same-owner --no-same-permissions --strip-components=1 -xzf /usr/src/opendaylight-0.2.2.tar.gz -C /opt/opendaylight-0.2.2

And this overall command:

mkdir -p /opt/opendaylight-0.2.2 && tar --no-same-owner --no-same-permissions --strip-components=1 -xzf /usr/src/opendaylight-0.2.2.tar.gz -C /opt/opendaylight-0.2.2

When executed:

[/usr/src]$ ls opendaylight-0.2.2.tar.gz
opendaylight-0.2.2.tar.gz
[/usr/src]$ ls /opt
apacheds-2.0.0_M19  google  vagrant
[/usr/src]$ mkdir -p /opt/opendaylight-0.2.2 && tar --no-same-owner --no-same-permissions --strip-components=1 -xzf /usr/src/opendaylight-0.2.2.tar.gz -C /opt/opendaylight-0.2.2
[/usr/src]$ ls /opt
apacheds-2.0.0_M19  google  opendaylight-0.2.2  vagrant
[/usr/src]$ ls /opt/opendaylight-0.2.2
bin  configuration  data  deploy  etc  externalapps  lib  system  version.properties

This is the desired result - the default extract dir (distribution-karaf-0.2.2-Helium-SR2 in this case) was striped off and replaced with one named opendaylight-0.2.2 (the second level of the target param).

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