Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

shelljs

Package Overview
Dependencies
Maintainers
1
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

shelljs - npm Package Compare versions

Comparing version 0.0.4 to 0.0.5-pre1

2

package.json
{ "name": "shelljs"
, "version": "0.0.4"
, "version": "0.0.5pre1"
, "author": "Artur Adib <aadib@mozilla.com>"

@@ -4,0 +4,0 @@ , "description": "Portable Unix shell commands for Node.js"

@@ -345,5 +345,16 @@ //

if (fs.statSync(file).isFile()) {
fs.unlinkSync(file);
// Do not check for file writing permissions
if (options.force) {
_unlinkSync(file);
return;
}
if (isWriteable(file))
_unlinkSync(file);
else
error('permission denied: '+file, true);
return;
}
} // simple file

@@ -358,3 +369,3 @@ // Path is an existing directory, but no -r flag given

if (fs.statSync(file).isDirectory() && options.recursive) {
rmdirSyncRecursive(file);
rmdirSyncRecursive(file, options.force);
}

@@ -1030,3 +1041,3 @@ }); // forEach(file)

} catch(e) {
error('copyFileSync: could not write to dest file ('+destFile+')');
error('copyFileSync: could not write to dest file (code='+e.code+'):'+destFile);
}

@@ -1095,3 +1106,3 @@

// http://www.opensource.org/licenses/mit-license.php
function rmdirSyncRecursive(dir) {
function rmdirSyncRecursive(dir, force) {
var files;

@@ -1103,12 +1114,17 @@

for(var i = 0; i < files.length; i++) {
var currFile = fs.lstatSync(dir + "/" + files[i]);
var file = dir + "/" + files[i],
currFile = fs.lstatSync(file);
if(currFile.isDirectory()) // Recursive function back to the beginning
rmdirSyncRecursive(dir + "/" + files[i]);
if(currFile.isDirectory()) { // Recursive function back to the beginning
rmdirSyncRecursive(file);
}
else if(currFile.isSymbolicLink()) // Unlink symlinks
fs.unlinkSync(dir + "/" + files[i]);
else if(currFile.isSymbolicLink()) { // Unlink symlinks
if (force || isWriteable(file))
_unlinkSync(file);
}
else // Assume it's a file - perhaps a try/catch belongs here?
fs.unlinkSync(dir + "/" + files[i]);
if (force || isWriteable(file))
_unlinkSync(file);
}

@@ -1118,3 +1134,12 @@

// Huzzah for the shopkeep.
return fs.rmdirSync(dir);
var result;
try {
result = fs.rmdirSync(dir);
} catch(e) {
if (e.code === 'ENOTEMPTY')
error('directory not empty: ' + dir, true);
}
return result;
}; // rmdirSyncRecursive

@@ -1166,3 +1191,3 @@

fs.writeFileSync(testFile, ' ');
fs.unlinkSync(testFile);
_unlinkSync(testFile);
return dir;

@@ -1265,5 +1290,5 @@ } catch (e) {

if (fs.existsSync(scriptFile)) fs.unlinkSync(scriptFile);
if (fs.existsSync(stdoutFile)) fs.unlinkSync(stdoutFile);
if (fs.existsSync(codeFile)) fs.unlinkSync(codeFile);
if (fs.existsSync(scriptFile)) _unlinkSync(scriptFile);
if (fs.existsSync(stdoutFile)) _unlinkSync(stdoutFile);
if (fs.existsSync(codeFile)) _unlinkSync(codeFile);

@@ -1291,6 +1316,6 @@ fs.writeFileSync(scriptFile, script);

fs.unlinkSync(scriptFile);
fs.unlinkSync(stdoutFile);
fs.unlinkSync(codeFile);
fs.unlinkSync(sleepFile);
_unlinkSync(scriptFile);
_unlinkSync(stdoutFile);
_unlinkSync(codeFile);
_unlinkSync(sleepFile);

@@ -1348,1 +1373,31 @@ // True if successful, false if not

}
// Normalizes _unlinkSync() across platforms to match Unix behavior, i.e.
// file can be unlinked even if it's read-only, see joyent/node#3006
function _unlinkSync(file) {
try {
fs.unlinkSync(file);
} catch(e) {
// Try to override file permission
if (e.code === 'EPERM') {
fs.chmodSync(file, '0666');
fs.unlinkSync(file);
} else {
throw e;
}
}
}
// Hack to determine if file has write permissions for current user
// Avoids having to check user, group, etc, but it's probably slow
function isWriteable(file) {
var writePermission = true;
try {
var __fd = fs.openSync(file, 'a');
fs.closeSync(__fd);
} catch(e) {
writePermission = false;
}
return writePermission;
}

@@ -13,3 +13,3 @@ var shell = require('..');

shell.rm('-rf', 'tmp');
shell.mkdir('tmp')
shell.mkdir('tmp');

@@ -108,2 +108,34 @@ //

// removal of a read-only file (unforced)
shell.mkdir('-p', 'tmp/readonly');
'asdf'.to('tmp/readonly/file1');
fs.chmodSync('tmp/readonly/file1', '0444'); // -r--r--r--
shell.rm('tmp/readonly/file1');
assert.equal(fs.existsSync('tmp/readonly/file1'), true); // bash's rm always asks before removing read-only files
// here we just assume "no"
// removal of a read-only file (forced)
shell.mkdir('-p', 'tmp/readonly');
'asdf'.to('tmp/readonly/file2');
fs.chmodSync('tmp/readonly/file2', '0444'); // -r--r--r--
shell.rm('-f', 'tmp/readonly/file2');
assert.equal(fs.existsSync('tmp/readonly/file2'), false);
// removal of a tree containing read-only files (unforced)
shell.mkdir('-p', 'tmp/tree2');
'asdf'.to('tmp/tree2/file1');
'asdf'.to('tmp/tree2/file2');
fs.chmodSync('tmp/tree2/file1', '0444'); // -r--r--r--
shell.rm('-r', 'tmp/tree2');
assert.equal(fs.existsSync('tmp/tree2/file1'), true);
assert.equal(fs.existsSync('tmp/tree2/file2'), false);
// removal of a tree containing read-only files (forced)
shell.mkdir('-p', 'tmp/tree');
'asdf'.to('tmp/tree/file1');
'asdf'.to('tmp/tree/file2');
fs.chmodSync('tmp/tree/file1', '0444'); // -r--r--r--
shell.rm('-rf', 'tmp/tree');
assert.equal(fs.existsSync('tmp/tree'), false);
shell.exit(123);

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc