fs-jetpack
Advanced tools
Comparing version 0.7.2 to 0.7.3
@@ -57,3 +57,15 @@ "use strict"; | ||
var symlinkPointsAt = fs.readlinkSync(inspectData.absolutePath); | ||
fs.symlinkSync(symlinkPointsAt, to); | ||
try { | ||
fs.symlinkSync(symlinkPointsAt, to); | ||
} catch (err) { | ||
// There is already file/symlink with this name on destination location. | ||
// Must erase it manually, otherwise system won't allow us to place symlink there. | ||
if (err.code === 'EEXIST') { | ||
fs.unlinkSync(to); | ||
// Retry... | ||
fs.symlinkSync(symlinkPointsAt, to); | ||
} else { | ||
throw err; | ||
} | ||
} | ||
} | ||
@@ -91,2 +103,3 @@ }; | ||
var promisedReadlink = Q.denodeify(fs.readlink); | ||
var promisedUnlink = Q.denodeify(fs.unlink); | ||
var promisedMkdirp = Q.denodeify(mkdirp); | ||
@@ -106,3 +119,22 @@ | ||
.then(function (symlinkPointsAt) { | ||
return promisedSymlink(symlinkPointsAt, to); | ||
var deferred = Q.defer(); | ||
promisedSymlink(symlinkPointsAt, to) | ||
.then(deferred.resolve) | ||
.catch(function (err) { | ||
if (err.code === 'EEXIST') { | ||
// There is already file/symlink with this name on destination location. | ||
// Must erase it manually, otherwise system won't allow us to place symlink there. | ||
promisedUnlink(to) | ||
.then(function () { | ||
// Retry... | ||
return promisedSymlink(symlinkPointsAt, to) | ||
}) | ||
.then(deferred.resolve, deferred.reject); | ||
} else { | ||
deferred.reject(err); | ||
} | ||
}); | ||
return deferred.promise; | ||
}); | ||
@@ -109,0 +141,0 @@ } |
{ | ||
"name": "fs-jetpack", | ||
"description": "Better file system API", | ||
"version": "0.7.2", | ||
"version": "0.7.3", | ||
"author": "Jakub Szwacz <jakub@szwacz.com>", | ||
@@ -6,0 +6,0 @@ "dependencies": { |
@@ -499,4 +499,33 @@ /* eslint-env jasmine */ | ||
it('can overwrite symlink', function (done) { | ||
var preparations = function () { | ||
helper.clearWorkingDir(); | ||
fse.mkdirsSync('to_copy'); | ||
fse.symlinkSync('some/file', 'to_copy/symlink'); | ||
fse.mkdirsSync('copied'); | ||
fse.symlinkSync('some/other_file', 'copied/symlink'); | ||
}; | ||
var expectations = function () { | ||
expect(fse.lstatSync('copied/symlink').isSymbolicLink()).toBe(true); | ||
expect(fse.readlinkSync('copied/symlink')).toBe('some/file'); | ||
}; | ||
// SYNC | ||
preparations(); | ||
jetpack.copy('to_copy', 'copied', { overwrite: true }); | ||
expectations(); | ||
// ASYNC | ||
preparations(); | ||
jetpack.copyAsync('to_copy', 'copied', { overwrite: true }) | ||
.then(function () { | ||
expectations(); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
199869
4953