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

gulp.dest error: eperm, open #1057

Closed
gokussx4 opened this issue May 5, 2015 · 2 comments
Closed

gulp.dest error: eperm, open #1057

gokussx4 opened this issue May 5, 2015 · 2 comments

Comments

@gokussx4
Copy link

gokussx4 commented May 5, 2015

I am just using gulp src and dest to copy files to a location where it will be hosted. Currently nothing has a handle on this dest directory. First time I run the task it completes successfully (folder didn't exist before gulp.dest was called). I run it again and now I see:

"C:\Program Files (x86)\JetBrains\WebStorm 10.0.2\bin\runnerw.exe" "C:\Program Files (x86)\nodejs\node.exe" C:\Users\user\AppData\Roaming\npm\node_modules\gulp\bin\gulp.js --color --gulpfile c:\Workspaces\xxx\Main\UI\WebUI\gulpfile.js copy-templates
[13:02:41] Using gulpfile c:\Workspaces\xxx\Main\UI\WebUI\gulpfile.js
[13:02:41] Starting 'copy-templates'...
[13:02:42] 'copy-templates' errored after 32 ms
[13:02:42] Error: EPERM, open 'C:\website\build\templates\dashboard.html'
    at Error (native)

Process finished with exit code 1

This is running on a windows 7 64bit os, here is the gulp code I am running:

var gulp       = require('gulp');
var buildDir = 'C:/website/build';
gulp.task('copy-templates', function() {
  return gulp.src('./client/templates/**/*.html')
    .pipe(gulp.dest(buildDir + '/templates'));
});

If I remove the read-only attribute that is applied to the C:\website\build directory I can successfully run the task over top the existing files.

@gokussx4
Copy link
Author

gokussx4 commented May 5, 2015

This may be a vinyl-fs issue with windows (or deeper). Thoughts?

@gokussx4
Copy link
Author

gokussx4 commented May 5, 2015

This is not a problem with gulp, so I apologize for posting it here but I will present a solution to those that found themselves here. Its because the source file has the read-only attribute on it (could be TFS or some other source control or other software putting that on the file). So when fs streams it the source to the destination it contains the same attributes.

Simple solution is to stream the source files into gulp-foreach and modify the file.stat.mode. I found I could do this by using bit flag math. I found that when the read-only attribute is applied the mode was missing 128,16, and 2 bits (146). If you turn those bits on the read-only is removed (seems backwards but it works).

var gulp       = require('gulp'),
      foreach  = require('gulp-foreach');

var buildDir = 'C:/website/build';

gulp.task('copy-templates', function() {
  return gulp.src('./client/templates/**/*.html')
    .pipe(foreach(function(stream, file){
      if((file.stat.mode & 146) == 0){
        file.stat.mode = file.stat.mode | 146;
      }
      return stream;
    }))
    .pipe(gulp.dest(buildDir + '/templates'));
});

It might also be cheaper to skip the check and just or the bits :)

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

1 participant