2016-06-29 65 views
1

我正在尝试构建一个过程,并且它看起来像gulp-chown不会给我正确的结果。gulp chown不会更改所有者

这是我跑:

gulp.task('clientDeploy', function() { 
    return gulp.src('client/dist/**/*') 
     .pipe(chown('rf', 'rfids')) 
     .pipe(gulp.dest('/var/www/html/dashboard')); 
}); 

吞气脚本以root身份运行,效果显着。

结果是这样的:

drwxr-xr-x 2 root root 4.0K Jun 29 12:57 css/ 
drwxr-xr-x 2 root root 4.0K Jun 29 12:57 fonts/ 
drwxr-xr-x 2 root root 4.0K Jun 29 12:57 icons/ 
drwxr-xr-x 3 root root 4.0K Jun 29 12:57 images/ 
drwxr-xr-x 2 root root 4.0K Jun 29 12:57 js/ 
-rw-rw-r-- 1 root root 8.3K Jun 29 13:15 events-panel.html 
-rw-r--r-- 1 root root 20K Jun 29 13:15 index.html 
-rw-rw-r-- 1 root root 8.2K Jun 29 13:15 main-panel.html 

我已经在GitHub上阅读here,问题可能与gulp.dest()不读取文件的元数据,并使用用户在运行命令。

有没有人遇到过这个并解决了它?

+0

你是用sudo还是以root身份运行gulp? – YOU

+0

随着sudo,它是整个服务器的更大的构建系统的一部分 – Finkel

+0

可能会使用chown后gulp.dest(交换,两个管道) – YOU

回答

0

这是vinyl-fs中的一个错误。当它将文件写入磁盘时,它将承认file.stat.mode(其中file是对象的vinylFile对象),但它完全忽略了file.stat.uidfile.stat.gid的值。

它看起来像vinyl-fs代码库中的fixed,但AFAIK目前还没有包含该修复程序的版本。

有人在错误报告中提到你已经克隆了gulp-chown,但我不认为这是必要的。我只是改变了文件所有权gulp.dest完成工作后:

import gulp from "gulp"; 
import es from "event-stream"; 
import fs from "fs"; 

gulp.task("build", 
     () => gulp.src("src/**/*") 
      .pipe(gulp.dest("build")) 
      .pipe(es.map((file, callback) => { 
       fs.chown(file.path, file.stat.uid, file.stat.gid, 
         (err) => callback(err, file)); 
      }))); 

你看,我只是用file.stat.uidfile.stat.gid。我的目标是保存源文件拥有的所有权。 (是的,因为vinyl-fs默认情况下甚至不会这么做这个)。你可以放任何你想要的uidgid

+0

我有一个系统,我每次都在不同的机器上构建和安装,因此我无法预先知道用户和组标识... 我现在使用的只是一个bash脚本,它在gulp完成后运行,并将用户和组更改为正确的用户和组。 – Finkel

+0

我看不出有什么可能阻止你的bash脚本执行的'chown'操作在JavaScript中用gulp完成。 – Louis