-/* ---------------------------- */
-struct dir *
- adddir( vol, dir, path)
-struct vol *vol;
-struct dir *dir;
-struct path *path;
-{
- struct dir *cdir, *edir;
- int upathlen;
- char *name;
- char *upath;
- struct stat *st;
- int deleted;
-
- upath = path->u_name;
- name = path->m_name;
- st = &path->st;
- upathlen = strlen(upath);
- if ((cdir = dirnew(name, upath)) == NULL) {
- LOG(log_error, logtype_afpd, "adddir: malloc: %s", strerror(errno) );
- return NULL;
- }
-
- cdir->d_did = get_id(vol, NULL, st, dir->d_did, upath, upathlen);
- if (cdir->d_did == 0)
- return NULL;
-
- if ((edir = dirinsert( vol, cdir ))) {
- /* it's not possible with LASTDID
- for CNID:
- - someone else have moved the directory.
- - it's a symlink inside the share.
- - it's an ID reused, the old directory was deleted but not
- the cnid record and the server've reused the inode for
- the new dir.
- for HASH (we should get ride of HASH)
- - someone else have moved the directory.
- - it's an ID reused as above
- - it's a hash duplicate and we are in big trouble
- */
- deleted = (edir->d_m_name == NULL);
- dirfreename(edir);
- edir->d_m_name = cdir->d_m_name;
- edir->d_u_name = cdir->d_u_name;
- free(cdir);
- cdir = edir;
- if (!cdir->d_parent || (cdir->d_parent == dir && !deleted))
- return cdir;
- /* the old was not in the same folder */
- if (!deleted)
- dirchildremove(cdir->d_parent, cdir);
- }
-
- /* parent/child directories */
- cdir->d_parent = dir;
- dirchildadd(dir, cdir);
- return( cdir );
-}