Skip to content

Commit

Permalink
Merge 49b439c into 4e1367f
Browse files Browse the repository at this point in the history
  • Loading branch information
boneskull committed Oct 24, 2019
2 parents 4e1367f + 49b439c commit ddcfc75
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
4 changes: 1 addition & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ const cpFileAsync = async (source, destination, options, progressEmitter) => {
progressEmitter.written = progressEmitter.size;
updateStats = true;
} catch (error) {
if (options.overwrite || error.code !== 'EEXIST') {
throw new CpFileError(`Cannot write to \`${destination}\`: ${error.message}`, error);
}
throw new CpFileError(`Cannot write to \`${destination}\`: ${error.message}`, error);
}

if (readError) {
Expand Down
7 changes: 4 additions & 3 deletions test/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import del from 'del';
import test from 'ava';
import uuid from 'uuid';
import sinon from 'sinon';
import cpFile from '..';
import assertDateEqual from './helpers/_assert';
import {buildEACCES, buildEIO, buildENOSPC, buildENOENT, buildEPERM} from './helpers/_fs-errors';
import cpFile from '..';

const THREE_HUNDRED_KILO = (100 * 3 * 1024) + 1;

Expand Down Expand Up @@ -75,8 +75,9 @@ test('overwrite when options are undefined', async t => {

test('do not overwrite when disabled', async t => {
fs.writeFileSync(t.context.destination, '');
await cpFile('license', t.context.destination, {overwrite: false});
t.is(fs.readFileSync(t.context.destination, 'utf8'), '');
const error = await t.throwsAsync(cpFile('license', t.context.destination, {overwrite: false}));
t.is(error.name, 'CpFileError', error.message);
t.is(error.code, 'EEXIST', error.message);
});

test('do not create `destination` on unreadable `source`', async t => {
Expand Down
2 changes: 1 addition & 1 deletion test/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import del from 'del';
import test from 'ava';
import uuid from 'uuid';
import sinon from 'sinon';
import cpFile from '..';
import assertDateEqual from './helpers/_assert';
import {buildEACCES, buildENOSPC, buildEBADF, buildEPERM} from './helpers/_fs-errors';
import cpFile from '..';

const THREE_HUNDRED_KILO = (100 * 3 * 1024) + 1;

Expand Down

0 comments on commit ddcfc75

Please sign in to comment.