Skip to content

Commit

Permalink
Don't move when source and dest paths are the same.
Browse files Browse the repository at this point in the history
  • Loading branch information
jdalton committed Mar 13, 2017
1 parent e771770 commit 8d978db
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
20 changes: 20 additions & 0 deletions lib/move/__tests__/move.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,26 @@ describe('move', () => {
})
})

it('should not move a file if source and destination are the same', done => {
const src = `${TEST_DIR}/a-file`
const dest = src

fse.move(src, dest, err => {
assert.ifError(err)
done()
})
})

it('should not move a directory if source and destination are the same', done => {
const src = `${TEST_DIR}/a-folder`
const dest = src

fse.move(src, dest, err => {
assert.ifError(err)
done()
})
})

it('should not overwrite the destination by default', done => {
const src = `${TEST_DIR}/a-file`
const dest = `${TEST_DIR}/a-folder/another-file`
Expand Down
4 changes: 3 additions & 1 deletion lib/move/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ function move (source, dest, options, callback) {
}

function doRename () {
if (overwrite) {
if (path.resolve(source) === path.resolve(dest)) {
setImmediate(callback)
} else if (overwrite) {
fs.rename(source, dest, err => {
if (!err) return callback()

Expand Down

0 comments on commit 8d978db

Please sign in to comment.