Return-Path: X-Original-To: apmail-commons-issues-archive@minotaur.apache.org Delivered-To: apmail-commons-issues-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id B69DD6F89 for ; Mon, 30 May 2011 14:55:29 +0000 (UTC) Received: (qmail 73791 invoked by uid 500); 30 May 2011 14:55:29 -0000 Delivered-To: apmail-commons-issues-archive@commons.apache.org Received: (qmail 73726 invoked by uid 500); 30 May 2011 14:55:29 -0000 Mailing-List: contact issues-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: issues@commons.apache.org Delivered-To: mailing list issues@commons.apache.org Received: (qmail 73711 invoked by uid 99); 30 May 2011 14:55:29 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 30 May 2011 14:55:29 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,T_RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.116] (HELO hel.zones.apache.org) (140.211.11.116) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 30 May 2011 14:55:28 +0000 Received: from hel.zones.apache.org (hel.zones.apache.org [140.211.11.116]) by hel.zones.apache.org (Postfix) with ESMTP id DCAC0E9A3B for ; Mon, 30 May 2011 14:54:47 +0000 (UTC) Date: Mon, 30 May 2011 14:54:47 +0000 (UTC) From: "Dmytro Polivenok (JIRA)" To: issues@commons.apache.org Message-ID: <168216243.53533.1306767287899.JavaMail.tomcat@hel.zones.apache.org> Subject: [jira] [Issue Comment Edited] (VFS-229) The moveTo() method of the AbstractFileObject class doesn't work correct on Linux MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/VFS-229?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13041153#comment-13041153 ] Dmytro Polivenok edited comment on VFS-229 at 5/30/11 2:53 PM: --------------------------------------------------------------- attached patch for trunk and 1.0: if canRenameTo returns false as it on different mounts on linux copy and move will be performed instead of throwing exception. The same approach was implemented here org.apache.commons.io.FileUtils.moveFile was (Author: polivenok): attached patch with for trunk and 1.0: if canRenameTo returns false as it on different mounts on linux copy and move will be performed instead of throwing exception. The same approach was implemented here org.apache.commons.io.FileUtils.moveFile > The moveTo() method of the AbstractFileObject class doesn't work correct on Linux > --------------------------------------------------------------------------------- > > Key: VFS-229 > URL: https://issues.apache.org/jira/browse/VFS-229 > Project: Commons VFS > Issue Type: Bug > Affects Versions: 1.0 > Environment: Linux, two files on different mounts > Reporter: Kathrin Leufke > Attachments: VFS-229(1.0).patch, VFS-229(trunk).patch > > Original Estimate: 1h > Remaining Estimate: 1h > > Hi, > i used the moveTo() method of the AbstractFileObject class to move one file (for example) from file:///media/filedir1/test.tif to file:///media/filedir2/test.tif. > Filedir1 and filedir2 are different mounts. The canRenameTo() method returns true (= same filesystem) and the doRename() of the LocalFile class throws an error because rename failed: Could not rename "file:///media/filedir1/test.tif" to "file:///media/filedir2/test.tif". > Because of the different mounts a copy/delete is required. > I solved the problem for myself by surrounding just the doRename() call of the moveTo() method with try/catch and in case of an exception I try to copy/delete. > {code:title=AbstractFileObject.java|borderStyle=solid} > public void moveTo(FileObject destFile) throws FileSystemException > { > ... > if (canRenameTo(destFile)) > { > // issue rename on same filesystem > try > { > attach(); > //************************* > // TODO changed code > boolean bDoRename = false; > try // just catch exceptions from doRename > { > doRename(destFile); > bDoRename = true; > } > catch(Exception e) > { > // rename failed, try copy/delete (code from else) > copyDelete(destFile); > } > if(bDoRename) > { > (FileObjectUtils.getAbstractFileObject(destFile)).handleCreate(getType()); > > destFile.close(); // now the destFile is no longer imaginary. force reattach. > > handleDelete(); // fire delete-events. This file-object (src) is like deleted. > } > // TODO ends > //************************* > } > catch (final RuntimeException re) > { > throw re; > } > catch (final Exception exc) > { > throw new FileSystemException("vfs.provider/rename.error", new Object[] > { > getName(), > destFile.getName() > }, exc); > } > } > else > { > // different fs - do the copy/delete stuff > //************************* > // TODO change code, extract copy/delete method > copyDelete(destFile); } > > //************************* > } > } > private void copyDelete(FileObject destFile) throws FileSystemException > { > destFile.copyFrom(this, Selectors.SELECT_SELF); > if (((destFile.getType().hasContent() && destFile.getFileSystem().hasCapability(Capability.SET_LAST_MODIFIED_FILE)) || > (destFile.getType().hasChildren() && destFile.getFileSystem().hasCapability(Capability.SET_LAST_MODIFIED_FOLDER))) && > getFileSystem().hasCapability(Capability.GET_LAST_MODIFIED)) > { > destFile.getContent().setLastModifiedTime(this.getContent().getLastModifiedTime()); > } > deleteSelf(); > } > {code} -- This message is automatically generated by JIRA. For more information on JIRA, see: http://www.atlassian.com/software/jira