- rc++;
- ad_close(adp, ADFLAGS_HF);
- goto rename_retry;
- case EPERM:
- case EACCES :
- return( AFPERR_ACCESS );
- case EROFS:
- return AFPERR_VLOCK;
- default :
- return( AFPERR_PARAM );
+
+ /* We are here because :
+ * -there's no dest folder.
+ * -there's no .AppleDouble in the dest folder.
+ * if we use the struct adouble passed in parameter it will not
+ * create .AppleDouble if the file is already opened, so we
+ * use a diff one, it's not a pb,ie it's not the same file, yet.
+ */
+ memset(&ad, 0, sizeof(ad));
+ if (!ad_open(dst, ADFLAGS_HF, O_RDWR | O_CREAT, 0666, &ad)) {
+ ad_close(adp, ADFLAGS_HF);
+ if (!unix_rename( adsrc, ad_path( dst, 0 )) )
+ err = 0;
+ else
+ err = errno;
+ }
+ else { /* it's something else, bail out */
+ err = errno;
+ }
+ }
+ /* try to undo the data fork rename,
+ * we know we are on the same device
+ */
+ if (err) {
+ unix_rename( dst, src );
+ /* return the first error */
+ switch ( err) {
+ case ENOENT :
+ return AFPERR_NOOBJ;
+ case EPERM:
+ case EACCES :
+ return AFPERR_ACCESS ;
+ case EROFS:
+ return AFPERR_VLOCK;
+ default :
+ return AFPERR_PARAM ;
+ }