Node.JS:chown string的替代品

时间:2023-02-06 16:43:19

At this time, fs.chown requires int values for uid and gid.

此时,fs.chown需要uid和gid的int值。

So, what is the recommended way to get these int values from a UNIX-like system?

那么,从类UNIX系统中获取这些int值的推荐方法是什么?

Should I read /etc/passwd and /etc/group directly?
That does not seem like the right way to do it...

我应该直接读/ etc / passwd和/ etc / group吗?这似乎不是正确的方法......

3 个解决方案

#1


2  

You've probably solved it by now, but for future reference: the uid-number package is used by npm, so I think it can be safely assumed that it works (and it does for me).

您现在可能已经解决了这个问题,但是为了将来的参考:nid使用了uid-number包,所以我认为可以安全地假设它可以工作(并且它适用于我)。

#2


2  

Just call chown directly:

只需直接调用chown:

var exec = require( "child_process" ).exec;
exec( "chown user:group filename" );

#3


0  

I checked and found this: https://npmjs.org/package/getuid I haven't used it. caveat emptor.

我查了一下,发现了这个:https://npmjs.org/package/getuid我还没用过它。买者自负。

Personally, I like looking these up in a configuration file that the user supplies :)

就个人而言,我喜欢在用户提供的配置文件中查找这些内容:)

-daniel

#1


2  

You've probably solved it by now, but for future reference: the uid-number package is used by npm, so I think it can be safely assumed that it works (and it does for me).

您现在可能已经解决了这个问题,但是为了将来的参考:nid使用了uid-number包,所以我认为可以安全地假设它可以工作(并且它适用于我)。

#2


2  

Just call chown directly:

只需直接调用chown:

var exec = require( "child_process" ).exec;
exec( "chown user:group filename" );

#3


0  

I checked and found this: https://npmjs.org/package/getuid I haven't used it. caveat emptor.

我查了一下,发现了这个:https://npmjs.org/package/getuid我还没用过它。买者自负。

Personally, I like looking these up in a configuration file that the user supplies :)

就个人而言,我喜欢在用户提供的配置文件中查找这些内容:)

-daniel