-
Notifications
You must be signed in to change notification settings - Fork 773
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BREAKING: copy*(): allow copying broken symlinks (#779)
- Loading branch information
Showing
20 changed files
with
215 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
lib/copy-sync/__tests__/symlink.test.js → ...-sync/__tests__/copy-sync-symlink.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
'use strict' | ||
|
||
const fs = require('fs') | ||
const os = require('os') | ||
const fse = require('../..') | ||
const path = require('path') | ||
const assert = require('assert') | ||
const copy = require('../copy') | ||
|
||
/* global afterEach, beforeEach, describe, it */ | ||
|
||
describe('copy / broken symlink', () => { | ||
const TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'copy-broken-symlink') | ||
const src = path.join(TEST_DIR, 'src') | ||
const dest = path.join(TEST_DIR, 'dest') | ||
|
||
beforeEach(done => { | ||
fse.emptyDir(TEST_DIR, err => { | ||
assert.ifError(err) | ||
createFixtures(src, done) | ||
}) | ||
}) | ||
|
||
afterEach(done => fse.remove(TEST_DIR, done)) | ||
|
||
describe('when symlink is broken', () => { | ||
it('should not throw error if dereference is false', done => { | ||
copy(src, dest, err => { | ||
assert.strictEqual(err, null) | ||
done() | ||
}) | ||
}) | ||
|
||
it('should throw error if dereference is true', done => { | ||
copy(src, dest, { dereference: true }, err => { | ||
assert.strictEqual(err.code, 'ENOENT') | ||
done() | ||
}) | ||
}) | ||
}) | ||
}) | ||
|
||
function createFixtures (srcDir, callback) { | ||
fs.mkdir(srcDir, err => { | ||
let brokenFile | ||
let brokenFileLink | ||
|
||
if (err) return callback(err) | ||
|
||
try { | ||
brokenFile = path.join(srcDir, 'does-not-exist') | ||
brokenFileLink = path.join(srcDir, 'broken-symlink') | ||
fs.writeFileSync(brokenFile, 'does not matter') | ||
fs.symlinkSync(brokenFile, brokenFileLink, 'file') | ||
} catch (err) { | ||
callback(err) | ||
} | ||
|
||
// break the symlink now | ||
fse.remove(brokenFile, callback) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.