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

File has no permission entries, del returns exit code 0 / success #50

Closed
mspace opened this issue Jan 26, 2016 · 13 comments
Closed

File has no permission entries, del returns exit code 0 / success #50

mspace opened this issue Jan 26, 2016 · 13 comments
Assignees

Comments

@mspace
Copy link

mspace commented Jan 26, 2016

I'm using del to delete file like this (and in some cases directories *.css)

gulp.task("delete", function(cb) {
  del(["./deleteMe.txt"]).then(function (paths) { // returns a promise; https://github.com/sindresorhus/del
    console.log("Deleted files and folders: \n", paths.join('\n'));
    cb();
  }, function (reason) {
    cb("Failed to delete files " + reason);
  });
});

[08:55:51] Using gulpfile X:\Gulpfile.js
[08:55:51] Starting 'delete'...
[08:55:51] Finished 'delete' after 3.82 ms
Process terminated with code 0.
Deleted files and folders:

If the same task uses nodejs's fs it works, it reports error correctly:

fs.unlink("deleteMe.txt", function (reason) {
    console.log("Reason " + reason);
  });

Reason Error: EPERM: operation not permitted, unlink 'X:\deleteMe.txt'

deleteMe.txt permissions:

file_permissions

@SamVerschueren
Copy link
Contributor

Try returning the promise in the gulp task

gulp.task("delete", function() {
  return del(["./deleteMe.txt"]).then(function (paths) { // returns a promise; https://github.com/sindresorhus/del
    console.log("Deleted files and folders: \n", paths.join('\n'));
    cb();
  }, function (reason) {
    cb("Failed to delete files " + reason);
  });
});

@mspace
Copy link
Author

mspace commented Jan 26, 2016

In your case callback must be provided as a function argument (ReferenceError: cb is not defined). Actually I forgot to add cb parameter to function, thank you for notice. Still output is the same, no error. I believe there are two ways:

gulp.task("delete", function() {
  return del(["./deleteMe.txt"]
});

or with a callback

gulp.task("delete", function(cb) {
  del(["./deleteMe.txt"]).then(function (paths) {
    cb(); // ok
  }, function (reason) {
    cb("Failed to delete files " + reason); // fail
  });
});

@SamVerschueren
Copy link
Contributor

Oh, didn't notice the cb. A gulp task can handle a promise so your first example should work and should return an error.

Tested on Mac OSX

'use strict';

const gulp = require('gulp');
const del = require('del');

gulp.task('delete', () => {
    return del('./deleteMe.txt');
});

output

[09:35:24] Starting 'delete'...
[09:35:24] 'delete' errored after 8.21 ms
[09:35:24] Error: EPERM: operation not permitted, unlink '/Users/sam/Projects/playground/gulp-test/deleteMe.txt'
    at Error (native)

@mspace
Copy link
Author

mspace commented Jan 26, 2016

Tested your code, but on Windows 10 still no error.

[09:41:02] Using gulpfile X:\Gulpfile.js
[09:41:03] Starting 'delete'...
[09:41:03] Finished 'delete' after 5.92 ms
Process terminated with code 0.

I'm using "del": "2.2.0" and "gulp": "3.9.0",

@schnittstabil
Copy link
Collaborator

@mspace Does del delete your "./deleteMe.txt"? – at least on Linux it is possible to delete a file w/o permissions; you only need the permission of the folder…

@mspace
Copy link
Author

mspace commented Jan 26, 2016

@schnittstabil No, file stays on the filesystem. It does not get deleted. Permissions on the folder are set ok: full control modify, read & execute, list folder contents, read, write for currently logged-in user in this case me and some other users Administrators, ....

@schnittstabil
Copy link
Collaborator

Thanks for reporting it, it's a glob issue: isaacs/node-glob/issues/245

@datatypevoid
Copy link

I can also confirm this issue on Windows 10 64-bit with node 5.5.0 and npm 3.3.12. No matter what I do I cannot delete even the simplest directory with something like:

gulp.task('clean:docs', function () {
  return del([
    // here we use a globbing pattern to match everything inside the `docs` folder
    './docs/**/*'
  ]);
});

@schnittstabil
Copy link
Collaborator

@datatypevoid

even the simplest directory

That seems not related to this issue, you may try:

gulp.task('clean:docs', function () {
  console.log('current directory:', require('process').cwd());
  console.log('files:', globby.sync(['./docs/**/*']));
  return del(['./docs/**/*']);
});

@datatypevoid
Copy link

Sorry I was still recovering this morning when I wrote that, and I must admit I was half-reading the thread trying to get in the door. When I use that function, I get:

current directory: f:\sites\project-name-here
files: []

but the files and directories remain unaffected.

@schnittstabil
Copy link
Collaborator

@datatypevoid If f:\sites\project-name-here\docs exists, then it looks like a globby issue (del uses globby). Please open a new issue there.

@datatypevoid
Copy link

Sorry for my ignorance man. Thanks for your help though!

@sindresorhus
Copy link
Owner

Closing as isaacs/node-glob#245 was fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants