@@ -126,7 +126,9 @@ static int After(eio_req *req) {
126
126
case EIO_LINK:
127
127
case EIO_SYMLINK:
128
128
case EIO_CHMOD:
129
+ case EIO_FCHMOD:
129
130
case EIO_CHOWN:
131
+ case EIO_FCHOWN:
130
132
// These, however, don't.
131
133
argc = 1 ;
132
134
break ;
@@ -792,7 +794,7 @@ static Handle<Value> Read(const Arguments& args) {
792
794
}
793
795
794
796
795
- /* fs.chmod(fd , mode);
797
+ /* fs.chmod(path , mode);
796
798
* Wrapper for chmod(1) / EIO_CHMOD
797
799
*/
798
800
static Handle<Value> Chmod (const Arguments& args) {
@@ -808,16 +810,38 @@ static Handle<Value> Chmod(const Arguments& args) {
808
810
ASYNC_CALL (chmod, args[2 ], *path, mode);
809
811
} else {
810
812
int ret = chmod (*path, mode);
811
- if (ret != 0 ) return ThrowException (ErrnoException (errno, NULL , " " , *path));
813
+ if (ret != 0 ) return ThrowException (ErrnoException (errno, " chmod " , " " , *path));
812
814
return Undefined ();
813
815
}
814
816
}
815
817
816
818
817
- /* fs.chown (fd, uid, gid );
818
- * Wrapper for chown (1) / EIO_CHOWN
819
+ /* fs.fchmod (fd, mode );
820
+ * Wrapper for fchmod (1) / EIO_FCHMOD
819
821
*/
822
+ static Handle<Value> FChmod (const Arguments& args) {
823
+ HandleScope scope;
824
+
825
+ if (args.Length () < 2 || !args[0 ]->IsInt32 () || !args[1 ]->IsInt32 ()) {
826
+ return THROW_BAD_ARGS;
827
+ }
828
+ int fd = args[0 ]->Int32Value ();
829
+ mode_t mode = static_cast <mode_t >(args[1 ]->Int32Value ());
830
+
831
+ if (args[2 ]->IsFunction ()) {
832
+ ASYNC_CALL (fchmod, args[2 ], fd, mode);
833
+ } else {
834
+ int ret = fchmod (fd, mode);
835
+ if (ret != 0 ) return ThrowException (ErrnoException (errno, " fchmod" , " " , 0 ));
836
+ return Undefined ();
837
+ }
838
+ }
839
+
840
+
820
841
#ifdef __POSIX__
842
+ /* fs.chown(path, uid, gid);
843
+ * Wrapper for chown(1) / EIO_CHOWN
844
+ */
821
845
static Handle<Value> Chown (const Arguments& args) {
822
846
HandleScope scope;
823
847
@@ -837,7 +861,37 @@ static Handle<Value> Chown(const Arguments& args) {
837
861
ASYNC_CALL (chown, args[3 ], *path, uid, gid);
838
862
} else {
839
863
int ret = chown (*path, uid, gid);
840
- if (ret != 0 ) return ThrowException (ErrnoException (errno, NULL , " " , *path));
864
+ if (ret != 0 ) return ThrowException (ErrnoException (errno, " chown" , " " , *path));
865
+ return Undefined ();
866
+ }
867
+ }
868
+ #endif // __POSIX__
869
+
870
+
871
+ #ifdef __POSIX__
872
+ /* fs.fchown(fd, uid, gid);
873
+ * Wrapper for fchown(1) / EIO_FCHOWN
874
+ */
875
+ static Handle<Value> FChown (const Arguments& args) {
876
+ HandleScope scope;
877
+
878
+ if (args.Length () < 3 || !args[0 ]->IsInt32 ()) {
879
+ return THROW_BAD_ARGS;
880
+ }
881
+
882
+ if (!args[1 ]->IsInt32 () || !args[2 ]->IsInt32 ()) {
883
+ return ThrowException (Exception::Error (String::New (" User and Group IDs must be an integer." )));
884
+ }
885
+
886
+ int fd = args[0 ]->Int32Value ();
887
+ uid_t uid = static_cast <uid_t >(args[1 ]->Int32Value ());
888
+ gid_t gid = static_cast <gid_t >(args[2 ]->Int32Value ());
889
+
890
+ if (args[3 ]->IsFunction ()) {
891
+ ASYNC_CALL (fchown, args[3 ], fd, uid, gid);
892
+ } else {
893
+ int ret = fchown (fd, uid, gid);
894
+ if (ret != 0 ) return ThrowException (ErrnoException (errno, " fchown" , " " , 0 ));
841
895
return Undefined ();
842
896
}
843
897
}
@@ -948,8 +1002,13 @@ void File::Initialize(Handle<Object> target) {
948
1002
NODE_SET_METHOD (target, " write" , Write);
949
1003
950
1004
NODE_SET_METHOD (target, " chmod" , Chmod);
1005
+ NODE_SET_METHOD (target, " fchmod" , FChmod);
951
1006
#ifdef __POSIX__
1007
+ // NODE_SET_METHOD(target, "lchmod", LChmod);
1008
+
952
1009
NODE_SET_METHOD (target, " chown" , Chown);
1010
+ NODE_SET_METHOD (target, " fchown" , FChown);
1011
+ // NODE_SET_METHOD(target, "lchown", LChown);
953
1012
#endif // __POSIX__
954
1013
955
1014
NODE_SET_METHOD (target, " utimes" , UTimes);
0 commit comments