]> arthur.barton.de Git - netatalk.git/blobdiff - libatalk/cnid/cnid_update.c
Merge latest CNID DB code from HEAD.
[netatalk.git] / libatalk / cnid / cnid_update.c
index de1d7872509f300e75a9f4229e3f92fc0aef5bd0..b851a02c1fec67f68c955abfac8b843bf46f7b85 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: cnid_update.c,v 1.12.2.1 2001-12-03 05:05:51 jmarcus Exp $
+ * $Id: cnid_update.c,v 1.12.2.4 2002-02-09 20:29:02 jmarcus Exp $
  */
 
 #ifdef HAVE_CONFIG_H
@@ -42,8 +42,7 @@ int cnid_update(void *CNID, const cnid_t id, const struct stat *st,
 
 retry:
     if ((rc = txn_begin(db->dbenv, NULL, &tid, 0))) {
-        syslog(LOG_ERR, "cnid_update: Failed to begin transaction: %s",
-               db_strerror(rc));
+        syslog(LOG_ERR, "cnid_update: Failed to begin transaction: %s", db_strerror(rc));
         return rc;
     }
 
@@ -56,6 +55,11 @@ retry:
         switch (rc) {
         case DB_LOCK_DEADLOCK:
             goto retry;
+        case DB_NOTFOUND:
+            /* Silently fail here.  We're allowed to do this since this CNID
+             * might have been deleted out from under us, or someone has
+             * called cnid_lookup then cnid_update (which is redundant). */
+            return 0;
         default:
             goto update_err;
         }
@@ -97,6 +101,19 @@ retry:
     data.data = make_cnid_data(st, did, name, len);
     data.size = CNID_HEADER_LEN + len + 1;
 
+    /* Update the old CNID with the new info. */
+    key.data = (cnid_t *) &id;
+    key.size = sizeof(id);
+    if ((rc = db->db_cnid->put(db->db_cnid, tid, &key, &data, 0))) {
+        txn_abort(tid);
+        switch (rc) {
+        case DB_LOCK_DEADLOCK:
+            goto retry;
+        default:
+            goto update_err;
+        }
+    }
+
     /* Put in a new dev/ino mapping. */
     key.data = data.data;
     key.size = CNID_DEVINO_LEN;
@@ -125,24 +142,12 @@ retry:
         }
     }
 
-    /* Update the old CNID with the new info. */
-    key.data = (cnid_t *) &id;
-    key.size = sizeof(id);
-    if ((rc = db->db_cnid->put(db->db_cnid, tid, &key, &data, 0))) {
-        txn_abort(tid);
-        switch (rc) {
-        case DB_LOCK_DEADLOCK:
-            goto retry;
-        default:
-            goto update_err;
-        }
-    }
 
     return txn_commit(tid, 0);
 
 update_err:
     syslog(LOG_ERR, "cnid_update: Unable to update CNID %u: %s",
-           ntohl(id), db_strerror(rc));
+        ntohl(id), db_strerror(rc));
     return -1;
 }
 #endif /* CNID_DB */