X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=netatalk.git;a=blobdiff_plain;f=libatalk%2Fadouble%2Fad_write.c;fp=libatalk%2Fadouble%2Fad_write.c;h=4ae1cf60adf1cfcbd61907d20a5fc430c1f4d31a;hp=5cd3742d69f9890f3fa01a5148fc23fda7ae1e6f;hb=ab6e6f8ed24667ced438afe4df5997469a2ff53b;hpb=471d63120ea3d21bd9d6eb3b220d1e3eec419f68 diff --git a/libatalk/adouble/ad_write.c b/libatalk/adouble/ad_write.c index 5cd3742d..4ae1cf60 100644 --- a/libatalk/adouble/ad_write.c +++ b/libatalk/adouble/ad_write.c @@ -161,17 +161,22 @@ int ad_rtruncate(struct adouble *ad, const char *uname, const off_t size) { EC_INIT; -#ifndef HAVE_EAFD - if (ad->ad_vers == AD_VERSION_EA && size == 0) - EC_NEG1( unlink(ad->ad_ops->ad_path(uname, 0)) ); - else -#endif - EC_NEG1( sys_ftruncate(ad_reso_fileno(ad), size + ad->ad_eid[ ADEID_RFORK ].ade_off) ); + /* + * We can't delete 0 byte size resource forks either, because a + * fork may reference the adouble handle with an open fd for the + * file, which means we would only delete the directory entry, not + * the file. Subsequently all code that works with fork handles + * finds the fork open, so eg flushing a fork (ad_flush()) will + * recreate ._ files. The correct place to delete 0 byte sized + * resource forks is in of_closefork(). + */ + + EC_NEG1( sys_ftruncate(ad_reso_fileno(ad), size + ad->ad_eid[ ADEID_RFORK ].ade_off) ); + + ad->ad_rlen = size; EC_CLEANUP: - if (ret == 0) - ad->ad_rlen = size; - else + if (ret != 0) LOG(log_error, logtype_ad, "ad_rtruncate(\"%s\"): %s", fullpathname(uname), strerror(errno)); EC_EXIT;