X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=bin%2Fad%2Fad_rm.c;h=b32e659fad5ff73a833a0c6de20575adcde66fb5;hb=3a84db87064922ad10ac10cc1d6833380e575995;hp=8d25b341d6ab3fc980eb43d369f979f0eccfa3a8;hpb=515478117dbf17fd3ded7218a665ebaf95b09531;p=netatalk.git diff --git a/bin/ad/ad_rm.c b/bin/ad/ad_rm.c index 8d25b341..b32e659f 100644 --- a/bin/ad/ad_rm.c +++ b/bin/ad/ad_rm.c @@ -32,7 +32,6 @@ #include #include #include -#include #include #include #include @@ -133,7 +132,7 @@ static void usage_rm(void) exit(EXIT_FAILURE); } -int ad_rm(int argc, char *argv[]) +int ad_rm(int argc, char *argv[], AFPObj *obj) { int ch; @@ -166,7 +165,7 @@ int ad_rm(int argc, char *argv[]) for (int i = 0; argv[i] != NULL; i++) { /* Load .volinfo file for source */ - openvol(argv[i], &volume); + openvol(obj, argv[i], &volume); if (nftw(argv[i], rm, upfunc, 20, FTW_DEPTH | FTW_PHYS) == -1) { if (alarmed) { @@ -201,9 +200,10 @@ static int rm(const char *path, switch (statp->st_mode & S_IFMT) { case S_IFLNK: - if (volume.volinfo.v_path) { - if ((volume.volinfo.v_adouble == AD_VERSION2) - && STRCMP(path, == , ".AppleDouble")) { + if (volume.vol->v_path) { + if ((volume.vol->v_adouble == AD_VERSION2) + && (strstr(path, ".AppleDouble") != NULL)) { + /* symlink inside adouble dir */ if (unlink(path) != 0) badrm = rval = 1; break; @@ -211,8 +211,11 @@ static int rm(const char *path, /* Get CNID of Parent and add new childir to CNID database */ pdid = did; - cnid = cnid_for_path(&volume.volinfo, &volume.volume, path, &did); - if (cnid_delete(volume.volume.v_cdb, cnid) != 0) { + if ((cnid = cnid_for_path(volume.vol->v_cdb, volume.vol->v_path, path, &did)) == CNID_INVALID) { + SLOG("Error resolving CNID for %s", path); + return -1; + } + if (cnid_delete(volume.vol->v_cdb, cnid) != 0) { SLOG("Error removing CNID %u for %s", ntohl(cnid), path); return -1; } @@ -231,9 +234,10 @@ static int rm(const char *path, return FTW_SKIP_SUBTREE; } - if (volume.volinfo.v_path) { - if ((volume.volinfo.v_adouble == AD_VERSION2) - && STRCMP(path, == , ".AppleDouble")) { + if (volume.vol->v_path) { + if ((volume.vol->v_adouble == AD_VERSION2) + && (strstr(path, ".AppleDouble") != NULL)) { + /* should be adouble dir itself */ if (rmdir(path) != 0) { SLOG("Error removing dir \"%s\": %s", path, strerror(errno)); badrm = rval = 1; @@ -243,8 +247,11 @@ static int rm(const char *path, } /* Get CNID of Parent and add new childir to CNID database */ - did = cnid_for_path(&volume.volinfo, &volume.volume, path, &pdid); - if (cnid_delete(volume.volume.v_cdb, did) != 0) { + if ((did = cnid_for_path(volume.vol->v_cdb, volume.vol->v_path, path, &pdid)) == CNID_INVALID) { + SLOG("Error resolving CNID for %s", path); + return -1; + } + if (cnid_delete(volume.vol->v_cdb, did) != 0) { SLOG("Error removing CNID %u for %s", ntohl(did), path); return -1; } @@ -275,9 +282,10 @@ static int rm(const char *path, break; default: - if (volume.volinfo.v_path) { - if ((volume.volinfo.v_adouble == AD_VERSION2) - && STRCMP(path, == , ".AppleDouble")) { + if (volume.vol->v_path) { + if ((volume.vol->v_adouble == AD_VERSION2) + && (strstr(path, ".AppleDouble") != NULL)) { + /* file in adouble dir */ if (unlink(path) != 0) badrm = rval = 1; break; @@ -285,19 +293,17 @@ static int rm(const char *path, /* Get CNID of Parent and add new childir to CNID database */ pdid = did; - cnid = cnid_for_path(&volume.volinfo, &volume.volume, path, &did); - if (cnid_delete(volume.volume.v_cdb, cnid) != 0) { + if ((cnid = cnid_for_path(volume.vol->v_cdb, volume.vol->v_path, path, &did)) == CNID_INVALID) { + SLOG("Error resolving CNID for %s", path); + return -1; + } + if (cnid_delete(volume.vol->v_cdb, cnid) != 0) { SLOG("Error removing CNID %u for %s", ntohl(cnid), path); return -1; } - if (!Rflag) { - if (volume.volume.vfs->vfs_deletefile(&volume.volume, -1, path) != 0) { - SLOG("Error removing adouble file for: %s", path); - badrm = rval = 1; - break; - } - } + /* Ignore errors, because with -R adouble stuff is always alread gone */ + volume.vol->vfs->vfs_deletefile(volume.vol, -1, path); } if (unlink(path) != 0) {