Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't move when source and dest paths are the same. #378

Merged
merged 1 commit into from Mar 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 20 additions & 0 deletions lib/move/__tests__/move.test.js
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
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