Bug 196211 - [Move][FTP][Local] Move a folder to a directory that contains a folder by that name errors
Summary: [Move][FTP][Local] Move a folder to a directory that contains a folder by tha...
Status: CLOSED FIXED
Alias: None
Product: Target Management
Classification: Tools
Component: RSE (show other bugs)
Version: 2.0   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 2.0.1   Edit
Assignee: Kevin Doyle CLA
QA Contact: Martin Oberhuber CLA
URL:
Whiteboard:
Keywords: contributed
Depends on:
Blocks:
 
Reported: 2007-07-11 15:09 EDT by Kevin Doyle CLA
Modified: 2011-05-25 09:36 EDT (History)
2 users (show)

See Also:


Attachments
Move now just calls copy() and delete() (2.95 KB, patch)
2007-07-12 15:56 EDT, Kevin Doyle CLA
no flags Details | Diff
Try java File.renameTo if it returns false use copy/delete (1.64 KB, patch)
2007-07-13 10:57 EDT, Kevin Doyle CLA
no flags Details | Diff
Updates for Local and DStore move to use Java File.rename() (7.54 KB, patch)
2007-07-16 11:42 EDT, Kevin Doyle CLA
mober.at+eclipse: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Kevin Doyle CLA 2007-07-11 15:09:30 EDT
On Local and FTP Moving a folder from one directory to another where the destination contains a folder by the same name as the one you are moving errors.

Local Error Message:
RSEF1307E: SUB#0:same
--> same is the directory I copied

FTP Error Message:
RSEF1002E: SUB#0:550 Rename/move failure: Directory not empty
--> Issue is b/c Delete on a folder that is not empty doesn't work

DStore and SSH have different issue's and will be opening different bugs for those.

-----------Enter bugs above this line-----------
TM 2.0 Testing
installation : eclipse-SDK-3.3
RSE install  : RSE 2.0
java.runtime : Sun 1.5.0_11-b03
os.name:     : Windows XP, Service Pack 2
------------------------------------------------
Comment 1 Martin Oberhuber CLA 2007-07-12 11:14:53 EDT
Assigning to Kevin to Fix Local -- that one should be simple since DStore works properly, and it should be possible to just re-use the DStore code (copy & paste will be necessary).

Javier should look at the FTP issue -- I'm not sure if it can be fixed easily for FTP though since there are way fewer commands available. Javier Can you investigate?
Comment 2 Kevin Doyle CLA 2007-07-12 11:41:25 EDT
I'll look into the issue for Local.

Javier/Martin why does Delete not work if a folder is not empty for FTP?  I've noticed this is how it works in other FTP Clients as well and it's such a pain to remove everything under a folder before deleting it.  Is it to much work to recursively go through the subfolders/files and delete them before deleting the directory?   
Comment 3 Martin Oberhuber CLA 2007-07-12 11:45:15 EDT
The FTP protocol does not support it, but I agree that recursive delete would be a great value-add for RSE. Kevin can you file an enhancement request for it?
Comment 4 Javier Montalvo Orús CLA 2007-07-12 12:04:24 EDT
(In reply to comment #2)
> I'll look into the issue for Local.
> 
> Javier/Martin why does Delete not work if a folder is not empty for FTP?  I've
> noticed this is how it works in other FTP Clients as well and it's such a pain
> to remove everything under a folder before deleting it.  Is it to much work to
> recursively go through the subfolders/files and delete them before deleting the
> directory?   
> 
From FTP protocol, it is not allowed. Issuing the command to delete a folder not empty should return an error. We could go for recursively deleting everything under that folder, but we have to agree in this behaviour, since it's not the standard FTP one.
Comment 5 David McKnight CLA 2007-07-12 12:06:22 EDT
If you look at the code for LocalFileService, the delete appears to be recursive via the deleteContents() call.
Comment 6 Javier Montalvo Orús CLA 2007-07-12 12:12:45 EDT
In FTP, moving a folder to another folder containing a subfolder with the same name doesn't seem to be allowed. Even when selecting "Overwrite" in the duplicate file dialog and issuing a RNFR + RNTO set of commands, the result is an error:

550 /eclipse/TargetManagement/test22/test: Cannot create a file when that file already exists. 
Comment 7 Kevin Doyle CLA 2007-07-12 13:12:40 EDT
I've opened bug #196351, for the discussion on recursive delete for ftp.
Comment 8 Kevin Doyle CLA 2007-07-12 15:56:49 EDT
Created attachment 73699 [details]
Move now just calls copy() and delete()

Changed the code so no matter if the folder is virtual, archive, or just a normal folder they all perform copy() then a delete().  This is the same way DStore works.

Legal Message: I, Kevin Doyle, declare that I developed attached code from
scratch, without referencing any 3rd party materials except material licensed
under the EPL. I am authorized by my employer, IBM Canada Ltd. to make this
contribution under the EPL.
Comment 9 Martin Oberhuber CLA 2007-07-13 06:18:17 EDT
Hm... the patch removes an optimization from local move which may be important: If you want to move a 500MB file from X to Y and you do so by copy-then-delete, you may run out of disk space whereas a real move operation would succeed.

I would recommend the following approach instead - try the Java renameTo operation, and if it fails fall back to copy-then-delete. This is the kind of approach that the Eclipse EFS implementation also does in LocalFile.move() -- in fact LocalFile.move() does an additional check to see whether source.getCanonicalPath().equals(tgt.getCanonicalPath()). I think we should do that as well on Local.

I think that the dstore implementation should also be changed to do what LocalFile.move() does and if it fails, fall back to the copy-then-delete approach just like LocalFile.move().

boolean movedOk = false;
if (!sourceIsVirtual && !targetIsVirtual && !targetIsArchive) {
    movedOk = source.renameTo(tgt);
}
if (!movedOk) {
    if (copy(src, tgt)) {
        movedOk = delete(src);
    }
}
return movedOk;
Comment 10 Martin Oberhuber CLA 2007-07-13 06:44:20 EDT
(In reply to comment #6)
> In FTP, moving a folder to another folder containing a subfolder with the same
> name doesn't seem to be allowed. Even when selecting "Overwrite" in the
> duplicate file dialog and issuing a RNFR + RNTO set of commands, the result is
> an error:

Provided that this error is properly displayed to the user, I'd be OK with keeping this functionality. Since we cannot easily merge the folders on an FTP-only connection, it's OK if the user must manually delete the target first (doing a recursive delete), then copy or move the source.
Comment 11 Kevin Doyle CLA 2007-07-13 10:57:11 EDT
Created attachment 73745 [details]
Try java File.renameTo if it returns false use copy/delete

I've updated the patch, so it will try to use Java File.renameTo() and if it returns false we use copy/delete.  File.renameTo() will return false whenever the destination exists.

Legal Message: I, Kevin Doyle, declare that I developed attached code from
scratch, without referencing any 3rd party materials except material licensed
under the EPL. I am authorized by my employer, IBM Canada Ltd. to make this
contribution under the EPL.
Comment 12 Kevin Doyle CLA 2007-07-13 11:08:58 EDT
(In reply to comment #10)
> (In reply to comment #6)
> > In FTP, moving a folder to another folder containing a subfolder with the same
> > name doesn't seem to be allowed. Even when selecting "Overwrite" in the
> > duplicate file dialog and issuing a RNFR + RNTO set of commands, the result is
> > an error:
> 
> Provided that this error is properly displayed to the user, I'd be OK with
> keeping this functionality. Since we cannot easily merge the folders on an
> FTP-only connection, it's OK if the user must manually delete the target first
> (doing a recursive delete), then copy or move the source.
> 

We get an error dialog, but the details message is related to the Directory not being empty, which doesn't say exactly why the Move failed.

Error Dialog:
Operation failed. File system input or output error
Details: Message reported from file system: 550 Rename/move failure: Directory not empty

It would be better if it reported that it didn't work as the destination contains a folder by the same name.

It would be even better if the Duplicate Name Collision dialog didn't allow you to choose the Overwrite operation in this case.
Comment 13 Martin Oberhuber CLA 2007-07-13 11:11:32 EDT
Feel free to file a separate bug for that, but I'm OK with the current situation.
Comment 14 Kevin Doyle CLA 2007-07-13 11:23:56 EDT
(In reply to comment #13)
> Feel free to file a separate bug for that, but I'm OK with the current
> situation.
> 

I've opened up Bug 196471 for this issue.
Comment 15 Kevin Doyle CLA 2007-07-16 11:42:24 EDT
Created attachment 73857 [details]
Updates for Local and DStore move to use Java File.rename()

Dave, I've changed how DStoreFileService.rename(...) works a bit.  If you pass an emptry string or null parent then it will take the oldName and newName to be the full paths of the old and new renamed files.  This way we can use Java file.renameTo in the UniversalFileSystemMiner.handleRename(...) with the 1 line change in it.

What do you think?  Anything that should be changed?

Legal Message: I, Kevin Doyle, declare that I developed attached code from
scratch, without referencing any 3rd party materials except material licensed
under the EPL. I am authorized by my employer, IBM Canada Ltd. to make this
contribution under the EPL.
Comment 16 David McKnight CLA 2007-07-16 13:56:46 EDT
I'm okay with this.  I've committed the patch to cvs.
Comment 17 Kevin Doyle CLA 2007-07-20 11:03:41 EDT
Verified with I20070719-1300.