check unlink of non-empty directory

This commit is contained in:
rsc 2007-08-22 02:21:22 +00:00
parent bd39955ecc
commit c88bf235fe

View file

@ -782,6 +782,11 @@ subdir(void)
} }
write(fd, "ff", 2); write(fd, "ff", 2);
close(fd); close(fd);
if(unlink("dd") >= 0){
printf(1, "unlink dd (non-empty dir) succeeded!\n");
exit();
}
if(mkdir("/dd/dd") != 0){ if(mkdir("/dd/dd") != 0){
printf(1, "subdir mkdir dd/dd failed\n"); printf(1, "subdir mkdir dd/dd failed\n");
@ -817,6 +822,10 @@ subdir(void)
printf(1, "unlink dd/dd/ff failed\n"); printf(1, "unlink dd/dd/ff failed\n");
exit(); exit();
} }
if(open("dd/dd/ff", O_RDONLY) >= 0){
printf(1, "open (unlinked) dd/dd/ff succeeded\n");
exit();
}
if(chdir("dd") != 0){ if(chdir("dd") != 0){
printf(1, "chdir dd failed\n"); printf(1, "chdir dd failed\n");
@ -826,6 +835,10 @@ subdir(void)
printf(1, "chdir dd/../../dd failed\n"); printf(1, "chdir dd/../../dd failed\n");
exit(); exit();
} }
if(chdir("dd/../../../dd") != 0){
printf(1, "chdir dd/../../dd failed\n");
exit();
}
if(chdir("./..") != 0){ if(chdir("./..") != 0){
printf(1, "chdir ./.. failed\n"); printf(1, "chdir ./.. failed\n");
exit(); exit();
@ -842,8 +855,8 @@ subdir(void)
} }
close(fd); close(fd);
if(open("dd/dd/ff", 0) >= 0){ if(open("dd/dd/ff", O_RDONLY) >= 0){
printf(1, "open dd/dd/ff succeeded!\n"); printf(1, "open (unlinked) dd/dd/ff succeeded!\n");
exit(); exit();
} }
@ -916,9 +929,18 @@ subdir(void)
printf(1, "unlink dd/ff failed\n"); printf(1, "unlink dd/ff failed\n");
exit(); exit();
} }
if(unlink("dd") == 0){
// unlink dd/dd printf(1, "unlink non-empty dd succeeded!\n");
// unlink dd exit();
}
if(unlink("dd/dd") < 0){
printf(1, "unlink dd/dd failed\n");
exit();
}
if(unlink("dd") < 0){
printf(1, "unlink dd failed\n");
exit();
}
printf(1, "subdir ok\n"); printf(1, "subdir ok\n");
} }