* 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) {
* 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",
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);
* 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
*
* @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;
* @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,
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;
}
}
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 );
}
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);
(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;
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) {
/* 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");
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);
}
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);
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));
}
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);
/*
- * $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>
*
/* --------------- */
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;