isaacs/node-tar — Issue #7: Can't extract tar components into directory that doesn't have +x permission.
Author: danfuzz
Created: 2012-02-28 22:04:07+00:00
State: open

If a tarball contains a directory that isn't set to be searchable (+x permission flag), then the "tar" module will fail to extract its contents.

This is admittedly an odd corner case, but it came up in practice (see [Hogan issue #52](https://github.com/twitter/hogan.js/issues/52)). And, FWIW, the traditional "tar" clients seem to handle this case, even though the resulting output isn't particularly useful.

Here's a quick script that demos the problem.

```shell
#!/bin/bash

# Set up the example tarfile.
curl -k -o hogan.tar.gz https://registry.npmjs.org/hogan/-/hogan-1.0.5-dev.tgz
rm -f hogan.tar
gunzip hogan.tar.gz

# Clean up from last run.
chmod -R +x out; rm -rf out
rm -rf node_modules

# Problem!
npm install 'tar@~0.1.12'
node -e '
var fs = require("fs");
var tar = require("tar");
fs.createReadStream("hogan.tar")
.pipe(tar.Extract({ type: "Directory", path: "out" }));'
```

When I run this, I consistently get an error along the lines of:

```
Error: EACCES, permission denied '[...]/out/package/bin/hulk'
```

which is explained by the fact that the `bin` directory in the tarball isn't set to be searchable. I'd guess that the traditional tar utilities always create searchable directories and then only change permissions after extraction.

I hope this helps!