- newpath = obj->oldtmp;
- strcpy( newpath, mtoupath(vol, ibuf ));
-
- if ((vol->v_flags & AFPVOL_NOHEX) && strchr(newpath, '/'))
- return AFPERR_PARAM;
-
- if (!validupath(vol, newpath))
- return AFPERR_EXIST;
-
- /* the strdiacasecmp deals with case-insensitive, case preserving
- filesystems */
- if (stat( newpath, &st ) == 0 && strdiacasecmp(path, ibuf))
- return( AFPERR_EXIST );
-
- upath = mtoupath(vol, path);
-
-#if AD_VERSION > AD_VERSION1
- id = cnid_get(vol->v_db, curdir->d_did, upath, strlen(upath));
-#endif
-
- if ( rename( upath, newpath ) < 0 ) {
- switch ( errno ) {
- case ENOENT :
- return( AFPERR_NOOBJ );
- case EACCES :
- return( AFPERR_ACCESS );
- default :
- return( AFPERR_PARAM );
- }
- }
-
-#if AD_VERSION > AD_VERSION1
- if (stat(newpath, &st) < 0) /* this shouldn't fail */
- return AFPERR_MISC;
- cnid_update(vol->v_db, id, &st, curdir->d_did, newpath, strlen(newpath));
-#endif
-
- if ( !odir ) {
- newadpath = obj->newtmp;
- strcpy( newadpath, ad_path( newpath, 0 ));
- if ( rename( ad_path( upath, 0 ), newadpath ) < 0 ) {
- if ( errno == ENOENT ) { /* no adouble header file */
- if (( unlink( newadpath ) < 0 ) && ( errno != ENOENT )) {
- return( AFPERR_PARAM );
- }
- goto out;
- }
- return( AFPERR_PARAM );
- }
-
- memset(&ad, 0, sizeof(ad));
- if ( ad_open( newpath, ADFLAGS_HF, O_RDWR|O_CREAT, 0666,
- &ad) < 0 ) {
- return( AFPERR_PARAM );
- }
- } else {
- int isad = 1;
-
- memset(&ad, 0, sizeof(ad));
- if ( ad_open( newpath, vol_noadouble(vol)|ADFLAGS_HF|ADFLAGS_DIR,
- O_RDWR|O_CREAT, 0666, &ad) < 0 ) {
- if (!((errno == ENOENT) && vol_noadouble(vol)))
- return( AFPERR_PARAM );
- isad = 0;
- }
- if ((buf = realloc( odir->d_name, plen + 1 )) == NULL ) {
- syslog( LOG_ERR, "afp_rename: realloc: %m" );
- if (isad) {
- ad_flush(&ad, ADFLAGS_HF); /* in case of create */
- ad_close(&ad, ADFLAGS_HF);
- }
- return AFPERR_MISC;
- }
- odir->d_name = buf;
- strcpy( odir->d_name, ibuf );
- if (!isad)
- goto out;
- }
-
- ad_setentrylen( &ad, ADEID_NAME, plen );
- memcpy( ad_entry( &ad, ADEID_NAME ), ibuf, plen );
- ad_flush( &ad, ADFLAGS_HF );
- ad_close( &ad, ADFLAGS_HF );
-
-out:
- setvoltime(obj, vol );
-
- /* if it's still open, rename the ofork as well. */
- if (of_rename(vol, curdir, path, curdir, ibuf) < 0)
- return AFPERR_MISC;