ref: 53e0e51cbb94b5cb6f4bba729e62dec3b544f14e
parent: cbfc955b8df9b44c5aae452680e0246f6a309102
author: cinap_lenrek <cinap_lenrek@localhost>
date: Tue May 3 12:56:50 EDT 2011
ape: fix broken chmod for directories. (makes hg work again)
--- a/sys/src/ape/lib/ap/plan9/chmod.c
+++ b/sys/src/ape/lib/ap/plan9/chmod.c
@@ -7,14 +7,20 @@
int
chmod(const char *path, mode_t mode)
{
- Dir d;
+ Dir d, *dir;
- _nulldir(&d);
- d.mode = mode & 0777;
- if(_dirwstat(path, &d) < 0){
- _syserrno();
+ dir = _dirstat(path);
+ if(dir == nil){
+error:
+ _syserrno();
return -1;
}
+ _nulldir(&d);
+ d.mode = (dir->mode & ~0777) | (mode & 0777);
+ free(dir);
+ if(_dirwstat(path, &d) < 0)
+ goto error;
+
return 0;
}
@@ -21,13 +27,19 @@
int
fchmod(int fd, mode_t mode)
{
- Dir d;
+ Dir d, *dir;
- _nulldir(&d);
- d.mode = mode & 0777;
- if(_dirfwstat(fd, &d) < 0){
- _syserrno();
+ dir = _dirfstat(fd);
+ if(dir == nil){
+error:
+ _syserrno();
return -1;
}
+ _nulldir(&d);
+ d.mode = (dir->mode & ~ 0777) | (mode & 0777);
+ free(dir);
+ if(_dirfwstat(fd, &d) < 0)
+ goto error;
+
return 0;
}