Return-Path: Delivered-To: apmail-commons-commits-archive@locus.apache.org Received: (qmail 84707 invoked from network); 24 May 2008 11:26:01 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 24 May 2008 11:26:01 -0000 Received: (qmail 99099 invoked by uid 500); 24 May 2008 11:26:02 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 99054 invoked by uid 500); 24 May 2008 11:26:02 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 99045 invoked by uid 99); 24 May 2008 11:26:02 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 24 May 2008 04:26:02 -0700 X-ASF-Spam-Status: No, hits=-1998.6 required=10.0 tests=ALL_TRUSTED,TVD_FUZZY_SYMBOL X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 24 May 2008 11:25:15 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 05844238896D; Sat, 24 May 2008 04:25:37 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r659795 - /commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ftp/FtpFileObject.java Date: Sat, 24 May 2008 11:25:36 -0000 To: commits@commons.apache.org From: imario@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080524112537.05844238896D@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: imario Date: Sat May 24 04:25:36 2008 New Revision: 659795 URL: http://svn.apache.org/viewvc?rev=659795&view=rev Log: VFS-210: fixed ftp filesystem to avoid lookup of parent directory on resolve Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ftp/FtpFileObject.java Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ftp/FtpFileObject.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ftp/FtpFileObject.java?rev=659795&r1=659794&r2=659795&view=diff ============================================================================== --- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ftp/FtpFileObject.java (original) +++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ftp/FtpFileObject.java Sat May 24 04:25:36 2008 @@ -191,7 +191,7 @@ */ private void getInfo(boolean flush) throws IOException { - final FtpFileObject parent = (FtpFileObject) FileObjectUtils.getAbstractFileObject(getParent()); + final FtpFileObject parent = (FtpFileObject) FileObjectUtils.getAbstractFileObject(getParent()); FTPFile newFileInfo; if (parent != null) { @@ -225,7 +225,14 @@ { inRefresh = true; super.refresh(); - try + + synchronized (getFileSystem()) + { + this.fileInfo = null; + } + + /* VFS-210 + try { // this will tell the parent to recreate its children collection getInfo(true); @@ -234,6 +241,7 @@ { throw new FileSystemException(e); } + */ } finally { @@ -247,8 +255,11 @@ */ protected void doDetach() { - this.fileInfo = null; - children = null; + synchronized (getFileSystem()) + { + this.fileInfo = null; + children = null; + } } /** @@ -285,8 +296,11 @@ if (getType().equals(FileType.IMAGINARY)) { // file is deleted, avoid server lookup - this.fileInfo = null; - return; + synchronized (getFileSystem()) + { + this.fileInfo = UNKNOWN; + } + return; } getInfo(true); @@ -300,37 +314,44 @@ throws Exception { // VFS-210 - if (this.fileInfo == null) + synchronized (getFileSystem()) { - getInfo(false); + if (this.fileInfo == null) + { + getInfo(false); + } + + if (this.fileInfo == UNKNOWN) + { + return FileType.IMAGINARY; + } + else if (this.fileInfo.isDirectory()) + { + return FileType.FOLDER; + } + else if (this.fileInfo.isFile()) + { + return FileType.FILE; + } + else if (this.fileInfo.isSymbolicLink()) + { + return getLinkDestination().getType(); + } } - if (this.fileInfo == UNKNOWN) - { - return FileType.IMAGINARY; - } - else if (this.fileInfo.isDirectory()) - { - return FileType.FOLDER; - } - else if (this.fileInfo.isFile()) - { - return FileType.FILE; - } - else if (this.fileInfo.isSymbolicLink()) - { - return getLinkDestination().getType(); - } - - throw new FileSystemException("vfs.provider.ftp/get-type.error", getName()); + throw new FileSystemException("vfs.provider.ftp/get-type.error", getName()); } private FileObject getLinkDestination() throws FileSystemException { if (linkDestination == null) { - final String path = this.fileInfo.getLink(); - FileName relativeTo = getName().getParent(); + final String path; + synchronized (getFileSystem()) + { + path = this.fileInfo.getLink(); + } + FileName relativeTo = getName().getParent(); if (relativeTo == null) { relativeTo = getName(); @@ -344,12 +365,15 @@ protected FileObject[] doListChildrenResolved() throws Exception { - if (this.fileInfo != null && this.fileInfo.isSymbolicLink()) - { - return getLinkDestination().getChildren(); - } + synchronized (getFileSystem()) + { + if (this.fileInfo != null && this.fileInfo.isSymbolicLink()) + { + return getLinkDestination().getChildren(); + } + } - return null; + return null; } /** @@ -414,57 +438,63 @@ */ protected void doDelete() throws Exception { - final boolean ok; - final FtpClient ftpClient = ftpFs.getClient(); - try - { - if (this.fileInfo.isDirectory()) - { - ok = ftpClient.removeDirectory(relPath); - } - else - { - ok = ftpClient.deleteFile(relPath); - } - } - finally - { - ftpFs.putClient(ftpClient); - } - - if (!ok) - { - throw new FileSystemException("vfs.provider.ftp/delete-file.error", getName()); - } - this.fileInfo = null; - children = EMPTY_FTP_FILE_MAP; - } + synchronized (getFileSystem()) + { + final boolean ok; + final FtpClient ftpClient = ftpFs.getClient(); + try + { + if (this.fileInfo.isDirectory()) + { + ok = ftpClient.removeDirectory(relPath); + } + else + { + ok = ftpClient.deleteFile(relPath); + } + } + finally + { + ftpFs.putClient(ftpClient); + } + + if (!ok) + { + throw new FileSystemException("vfs.provider.ftp/delete-file.error", getName()); + } + this.fileInfo = null; + children = EMPTY_FTP_FILE_MAP; + } + } /** * Renames the file */ protected void doRename(FileObject newfile) throws Exception { - final boolean ok; - final FtpClient ftpClient = ftpFs.getClient(); - try - { - String oldName = getName().getPath(); - String newName = newfile.getName().getPath(); - ok = ftpClient.rename(oldName, newName); - } - finally - { - ftpFs.putClient(ftpClient); - } - - if (!ok) - { - throw new FileSystemException("vfs.provider.ftp/rename-file.error", new Object[]{getName().toString(), newfile}); - } - this.fileInfo = null; - children = EMPTY_FTP_FILE_MAP; - } + synchronized (getFileSystem()) + { + final boolean ok; + final FtpClient ftpClient = ftpFs.getClient(); + try + { + String oldName = getName().getPath(); + String newName = newfile.getName().getPath(); + ok = ftpClient.rename(oldName, newName); + } + finally + { + ftpFs.putClient(ftpClient); + } + + if (!ok) + { + throw new FileSystemException("vfs.provider.ftp/rename-file.error", new Object[]{getName().toString(), newfile}); + } + this.fileInfo = null; + children = EMPTY_FTP_FILE_MAP; + } + } /** * Creates this file as a folder. @@ -494,15 +524,18 @@ */ protected long doGetContentSize() throws Exception { - if (this.fileInfo.isSymbolicLink()) - { - return getLinkDestination().getContent().getSize(); - } - else - { - return this.fileInfo.getSize(); - } - } + synchronized (getFileSystem()) + { + if (this.fileInfo.isSymbolicLink()) + { + return getLinkDestination().getContent().getSize(); + } + else + { + return this.fileInfo.getSize(); + } + } + } /** * get the last modified time on an ftp file @@ -511,23 +544,26 @@ */ protected long doGetLastModifiedTime() throws Exception { - if (this.fileInfo.isSymbolicLink()) - { - return getLinkDestination().getContent().getLastModifiedTime(); - } - else - { - Calendar timestamp = this.fileInfo.getTimestamp(); - if (timestamp == null) - { - return 0L; - } - else - { - return (timestamp.getTime().getTime()); - } - } - } + synchronized (getFileSystem()) + { + if (this.fileInfo.isSymbolicLink()) + { + return getLinkDestination().getContent().getLastModifiedTime(); + } + else + { + Calendar timestamp = this.fileInfo.getTimestamp(); + if (timestamp == null) + { + return 0L; + } + else + { + return (timestamp.getTime().getTime()); + } + } + } + } /** * Creates an input stream to read the file content from.