]> arthur.barton.de Git - netatalk.git/commitdiff
Adjust dircache for renamed files and minor fixes
authorFrank Lahm <franklahm@googlemail.com>
Mon, 27 Sep 2010 09:54:31 +0000 (11:54 +0200)
committerFrank Lahm <franklahm@googlemail.com>
Mon, 27 Sep 2010 09:54:31 +0000 (11:54 +0200)
etc/afpd/afp_avahi.c
etc/afpd/dircache.c
etc/afpd/directory.c
etc/afpd/directory.h
etc/afpd/file.c
etc/afpd/file.h
etc/afpd/filedir.c
include/atalk/cnid.h
libatalk/cnid/cnid.c

index fc3627116be216f301ec713f3ce29cedb72bb3a9..28c72e22424ae96b3bef20dd9f9759951eec9d94 100644 (file)
@@ -250,7 +250,7 @@ static void client_callback(AvahiClient *client,
  * neccessary config setting.
  */
 void av_zeroconf_setup(const AFPConfig *configs) {
-    int error, ret;
+    int error;
 
     /* initialize the struct that holds our config settings. */
     if (ctx) {
@@ -291,8 +291,6 @@ fail:
  * This function finally runs the loop impl.
  */
 int av_zeroconf_run(void) {
-    int ret;
-
     /* Finally, start the event loop thread */
     if (avahi_threaded_poll_start(ctx->threaded_poll) < 0) {
         LOG(log_error, logtype_afpd, "Failed to create thread: %s",
index f6f19f71c10ae139049a1fe4e3214258c2a97fb2..c641f249f4a85d361d580bdb8f97371aa33d2447 100644 (file)
@@ -527,7 +527,7 @@ void dircache_dump(void)
                 cfrombstring(dir->d_u_name));
     }
 
-    fprintf(dump, "\Secondary DID/name index:\n");
+    fprintf(dump, "\nSecondary DID/name index:\n");
     fprintf(dump, "       VID     DID    CNID STAT  PATH\n");
     fprintf(dump, "====================================================================\n");
     hash_scan_begin(&hs, index_didname);
index a6f7564341e7f8b3076d033636199d9a497c5d4f..ad76bd090f8dae8e6c25f4d33dfb5a617520ab7e 100644 (file)
@@ -757,7 +757,7 @@ void dir_free(struct dir *dir)
  * 3. Build fullpath and create struct dir.
  * 4. Add it to the cache.
  *
- * @param vol   (r) pointer to struct vol
+ * @param vol   (r) pointer to struct vol, possibly modified in callee
  * @param dir   (r) pointer to parrent directory
  * @param path  (rw) pointer to struct path with valid path->u_name
  * @param len   (r) strlen of path->u_name
@@ -766,7 +766,7 @@ void dir_free(struct dir *dir)
  *
  * @note Function also assigns path->m_name from path->u_name.
  */
-struct dir *dir_add(const struct vol *vol, const struct dir *dir, struct path *path, int len)
+struct dir *dir_add(struct vol *vol, const struct dir *dir, struct path *path, int len)
 {
     int err = 0;
     struct dir  *cdir = NULL;
@@ -907,6 +907,7 @@ int dir_remove(const struct vol *vol, struct dir *dir)
  * @param did       (r) new DID
  * @param new_mname (r) new mac-name
  * @param new_uname (r) new unix-name
+ * @param pdir_fullpath (r) new fullpath of parent dir
  */
 int dir_modify(const struct vol *vol,
                struct dir *dir,
@@ -944,7 +945,7 @@ int dir_modify(const struct vol *vol,
             dir->d_u_name = dir->d_m_name;
         } else {
             if ((dir->d_u_name = bfromcstr(new_uname)) == NULL) {
-                LOG(log_error, logtype_afpd, "renamedir: bassigncstr: %s", strerror(errno) );
+                LOG(log_error, logtype_afpd, "dir_modify: bassigncstr: %s", strerror(errno) );
                 return -1;
             }
         }
@@ -2201,11 +2202,6 @@ int renamedir(const struct vol *vol,
         ad_close_metadata( &ad);
     }
 
-    if (dir_modify(vol, dir, curdir->d_did, 0, newname, dst, curdir->d_fullpath) != 0) {
-        LOG(log_error, logtype_afpd, "renamedir: fatal error from dir_modify: %s -> %s", src, dst);
-        return AFPERR_MISC;
-    }
-
     return( AFP_OK );
 }
 
index 0fe65e7000af0f02fe5a7e3e7049e013d4c96e16..c9e193d96b23034a7180faa3627c7a56173116fd 100644 (file)
@@ -111,7 +111,7 @@ typedef int (*dir_loop)(struct dirent *, char *, void *);
 extern struct dir *dir_new(const char *mname, const char *uname, const struct vol *,
                            cnid_t pdid, cnid_t did, bstring fullpath); /* volume.c needs it once */
 extern void        dir_free (struct dir *);
-extern struct dir  *dir_add(const struct vol *, const struct dir *, struct path *, int);
+extern struct dir  *dir_add(struct vol *, const struct dir *, struct path *, int);
 extern int         dir_modify(const struct vol *vol, struct dir *dir, cnid_t pdid, cnid_t did,
                               const char *new_mname, const char *new_uname, bstring pdir_fullpath);
 extern int         dir_remove(const struct vol *vol, struct dir *dir);
index a1674601d3b39bfe40c7b745ccf22f1486755e03..8aef42de86f65d2f458861c37a094daf91e62259 100644 (file)
@@ -202,9 +202,27 @@ char *set_name(const struct vol *vol, char *data, cnid_t pid, char *name, cnid_t
                                  (1 << FILPBIT_FNUM) |\
                                  (1 << FILPBIT_UNIXPR)))
 
-/* -------------------------- */
-uint32_t get_id(struct vol *vol, struct adouble *adp,  const struct stat *st,
-                const cnid_t did, char *upath, const int len) 
+/*!
+ * @brief Get CNID for did/upath args both from database and adouble file
+ *
+ * 1. Get the objects CNID as stored in its adouble file
+ * 2. Get the objects CNID from the database
+ * 3. If there's a problem with a "dbd" database, fallback to "tdb" in memory
+ * 4. In case 2 and 3 differ, store 3 in the adouble file
+ *
+ * @param vol    (rw) volume
+ * @param adp    (rw) adouble struct of object upath, might be NULL
+ * @param st     (r) stat of upath, must NOT be NULL
+ * @param did    (r) parent CNID of upath
+ * @param upath  (r) name of object
+ * @param len    (r) strlen of upath
+ */
+uint32_t get_id(struct vol *vol,
+                struct adouble *adp, 
+                const struct stat *st,
+                const cnid_t did,
+                const char *upath,
+                const int len) 
 {
     static int first = 1;       /* mark if this func is called the first time */
     u_int32_t adcnid;
@@ -214,9 +232,9 @@ restart:
     if (vol->v_cdb != NULL) {
         /* prime aint with what we think is the cnid, set did to zero for
            catching moved files */
-        adcnid = ad_getid(adp, st->st_dev, st->st_ino, 0, vol->v_stamp);
+        adcnid = ad_getid(adp, st->st_dev, st->st_ino, 0, vol->v_stamp); /* (1) */
 
-           dbcnid = cnid_add(vol->v_cdb, st, did, upath, len, adcnid);
+           dbcnid = cnid_add(vol->v_cdb, st, did, upath, len, adcnid); /* (2) */
            /* Throw errors if cnid_add fails. */
            if (dbcnid == CNID_INVALID) {
             switch (errno) {
@@ -234,7 +252,7 @@ restart:
                 /* we have to do it here for "dbd" because it uses "lazy opening" */
                 /* In order to not end in a loop somehow with goto restart below  */
                 /*  */
-                if (first && (strcmp(vol->v_cnidscheme, "dbd") == 0)) {
+                if (first && (strcmp(vol->v_cnidscheme, "dbd") == 0)) { /* (3) */
                     cnid_close(vol->v_cdb);
                     free(vol->v_cnidscheme);
                     vol->v_cnidscheme = strdup("tdb");
@@ -268,9 +286,10 @@ restart:
                 goto exit;
             }
         }
-        else if (adp && (adcnid != dbcnid)) {
+        else if (adp && (adcnid != dbcnid)) { /* 4 */
             /* Update the ressource fork. For a folder adp is always null */
-            LOG(log_debug, logtype_afpd, "get_id: calling ad_setid. adcnid: %u, dbcnid: %u", htonl(adcnid), htonl(dbcnid));
+            LOG(log_note, logtype_afpd, "get_id: calling ad_setid(old: %u, new: %u)",
+                htonl(adcnid), htonl(dbcnid));
             if (ad_setid(adp, st->st_dev, st->st_ino, dbcnid, did, vol->v_stamp)) {
                 ad_flush(adp);
             }
index 3c64e7ddca603fe46c8f73de206fe3ed69fba262..483f6be61a4d264fe74910a6f8c66a22a3b29f35 100644 (file)
@@ -127,8 +127,12 @@ extern void *get_finderinfo (const struct vol *, const char *, struct adouble *,
 extern size_t mtoUTF8   (const struct vol *, const char *, size_t , char *, size_t );
 extern int  copy_path_name (const struct vol *, char *, char *i);
 
-extern uint32_t get_id  (struct vol *, struct adouble *, const struct stat *,
-                         const cnid_t , char *, const int );
+extern uint32_t get_id  (struct vol *,
+                         struct adouble *,
+                         const struct stat *,
+                         cnid_t ,
+                         const char *,
+                         int );
 
 /* FP functions */
 int afp_exchangefiles (AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf,  size_t *rbuflen);
index 74bbd2e897b64f364c5bad6e5c7b61fe51b9694e..095189ce2b84a0605d34e18f5b99c402ac6ae67c 100644 (file)
@@ -449,6 +449,18 @@ static int moveandrename(const struct vol *vol,
         if (stat(upath, st) < 0)
             return AFPERR_MISC;
 
+        if (dir_modify(vol,
+                       sdir,
+                       curdir->d_did,
+                       0,
+                       newname,
+                       upath,
+                       S_ISDIR(st->st_mode) ? curdir->d_fullpath : NULL) != 0) {
+            LOG(log_error, logtype_afpd, "moveandrename: dir_modify error: %s -> %s",
+                p, upath);
+            return AFPERR_MISC;
+        }
+
         /* fix up the catalog entry */
         cnid_update(vol->v_cdb, id, st, curdir->d_did, upath, strlen(upath));
     }
index 8dcb33fbcae5bdb89d038dbd954f9b7aa29025c3..5cd5ff7039103901fca2025e4e4787e3f8e26886 100644 (file)
@@ -111,7 +111,7 @@ struct _cnid_db *cnid_open(const char *volpath,
                            const char *cnidport); /* Only for dbd */
 
 cnid_t cnid_add(struct _cnid_db *cdb, const struct stat *st, const cnid_t did, 
-                       char *name, const size_t len, cnid_t hint);
+                       const char *name, const size_t len, cnid_t hint);
 
 int    cnid_delete(struct _cnid_db *cdb, cnid_t id);
 
index 263f24145063bac89aa7b0593a2a6d095f1de0cb..ca2190e5485ad274c3b8aa45ee76b73b9135baaa 100644 (file)
@@ -1,6 +1,4 @@
 /* 
- * $Id: cnid.c,v 1.13 2010-03-31 09:47:32 franklahm Exp $
- *
  * Copyright (c) 2003 the Netatalk Team
  * Copyright (c) 2003 Rafal Lewczuk <rlewczuk@pronet.pl>
  * 
@@ -216,7 +214,7 @@ u_int32_t flags;
 
 /* --------------- */
 cnid_t cnid_add(struct _cnid_db *cdb, const struct stat *st, const cnid_t did, 
-                       char *name, const size_t len, cnid_t hint)
+                const char *name, const size_t len, cnid_t hint)
 {
 cnid_t ret;