Gulp - Handle read-only permissions for dest files?

拜拜、爱过 提交于 2019-12-19 05:11:40

问题


I have image files with read-only attribute set in source folder. I need to copy them to destination folder in most cases several times in gulpfile.js.

I am trying to copy src-to-dest files like this:

gulp.task('copy-images', function () {
  gulp.src(path_resource_images + '**/*.jpg')
    .pipe(gulp.dest(path_app_images));
});

It works once when the dest folder in empty. But for all next calls I've got an exception that file is read-only in dest folder. How can I remove file attr read-only to make image-copy works every time I call it?


回答1:


You can use gulp-chmod to handle permissions on your files.

So if you want to set your images readable and writable for everybody, you could go with something like:

var chmod = require('gulp-chmod');

gulp.task('copy-images', function() {
  gulp.src(path_resource_images + '**/*.jpg')
    .pipe(chmod(666))
    .pipe(gulp.dest(path_app_images));
});



回答2:


By passing options attribute. Set mode value to specify permission for any folders that need to be created as output.

gulp.dest("destination-path-here", {"mode": "0777"})

cheers :-)




回答3:


rimraf can be used to avoid issues with TFS permissions (by deleting destination files before copying files)

var rimraf = require("rimraf");
gulp.task("images_clean", function (cb) {
    rimraf(imagesDest, cb);
});


来源:https://stackoverflow.com/questions/26540548/gulp-handle-read-only-permissions-for-dest-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!