You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by im...@apache.org on 2006/12/20 10:14:54 UTC

svn commit: r488989 - in /jakarta/commons/proper/vfs/trunk: core/src/main/java/org/apache/commons/vfs/provider/ core/src/main/java/org/apache/commons/vfs/provider/local/ core/src/main/java/org/apache/commons/vfs/provider/ram/ examples/src/main/java/org...

Author: imario
Date: Wed Dec 20 01:14:53 2006
New Revision: 488989

URL: http://svn.apache.org/viewvc?view=rev&rev=488989
Log:
VFS-104: throw exception if setting last modification time failed

Added:
    jakarta/commons/proper/vfs/trunk/examples/src/main/java/org/apache/commons/vfs/example/ChangeLastModificationTime.java   (with props)
Modified:
    jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/AbstractFileObject.java
    jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/DefaultFileContent.java
    jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/DelegateFileObject.java
    jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/local/LocalFile.java
    jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ram/RamFileObject.java

Modified: jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/AbstractFileObject.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/AbstractFileObject.java?view=diff&rev=488989&r1=488988&r2=488989
==============================================================================
--- jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/AbstractFileObject.java (original)
+++ jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/AbstractFileObject.java Wed Dec 20 01:14:53 2006
@@ -248,11 +248,28 @@
         throw new FileSystemException("vfs.provider/get-last-modified-not-supported.error");
     }
 
+	/**
+	 * Sets the last modified time of this file.  Is only called if
+	 * {@link #doGetType} does not return {@link FileType#IMAGINARY}.
+	 * <p/>
+	 * This implementation throws an exception.
+	 *
+	 * @return false if it was not possible to change the time
+	 */
+	protected boolean doSetLastModTime(final long modtime)
+		throws Exception
+	{
+		doSetLastModifiedTime(modtime);
+		return true;
+	}
+
     /**
      * Sets the last modified time of this file.  Is only called if
      * {@link #doGetType} does not return {@link FileType#IMAGINARY}.
      * <p/>
      * This implementation throws an exception.
+	 *
+	 * @deprecated use {@link #doSetLastModTime}
      */
     protected void doSetLastModifiedTime(final long modtime)
         throws Exception
@@ -978,7 +995,7 @@
     /**
      * Checks if this fileObject is the same file as <code>destFile</code> just with a different
      * name.<br />
-     * E.g. for case insensitive filesystems like windows. 
+     * E.g. for case insensitive filesystems like windows.
      */
     protected boolean isSameFile(FileObject destFile) throws FileSystemException
     {

Modified: jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/DefaultFileContent.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/DefaultFileContent.java?view=diff&rev=488989&r1=488988&r2=488989
==============================================================================
--- jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/DefaultFileContent.java (original)
+++ jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/DefaultFileContent.java Wed Dec 20 01:14:53 2006
@@ -186,8 +186,11 @@
         }
         try
         {
-            file.doSetLastModifiedTime(modTime);
-        }
+            if (!file.doSetLastModTime(modTime))
+			{
+				throw new FileSystemException("vfs.provider/set-last-modified.error", file);
+			}
+		}
         catch (final Exception e)
         {
             throw new FileSystemException("vfs.provider/set-last-modified.error", file, e);

Modified: jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/DelegateFileObject.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/DelegateFileObject.java?view=diff&rev=488989&r1=488988&r2=488989
==============================================================================
--- jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/DelegateFileObject.java (original)
+++ jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/DelegateFileObject.java Wed Dec 20 01:14:53 2006
@@ -268,11 +268,12 @@
     /**
      * Sets the last-modified time of this file.
      */
-    protected void doSetLastModifiedTime(final long modtime)
+    protected boolean doSetLastModTime(final long modtime)
         throws Exception
     {
         file.getContent().setLastModifiedTime(modtime);
-    }
+		return true;
+	}
 
     /**
      * Creates an input stream to read the file content from.

Modified: jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/local/LocalFile.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/local/LocalFile.java?view=diff&rev=488989&r1=488988&r2=488989
==============================================================================
--- jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/local/LocalFile.java (original)
+++ jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/local/LocalFile.java Wed Dec 20 01:14:53 2006
@@ -192,10 +192,10 @@
     /**
      * Sets the last modified time of this file.
      */
-    protected void doSetLastModifiedTime(final long modtime)
+    protected boolean doSetLastModTime(final long modtime)
         throws FileSystemException
     {
-        file.setLastModified(modtime);
+        return file.setLastModified(modtime);
     }
 
     /**

Modified: jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ram/RamFileObject.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ram/RamFileObject.java?view=diff&rev=488989&r1=488988&r2=488989
==============================================================================
--- jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ram/RamFileObject.java (original)
+++ jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ram/RamFileObject.java Wed Dec 20 01:14:53 2006
@@ -63,7 +63,7 @@
 
 	/*
 	 * (non-Javadoc)
-	 * 
+	 *
 	 * @see org.apache.commons.vfs.provider.AbstractFileObject#doGetType()
 	 */
 	protected FileType doGetType() throws Exception
@@ -73,7 +73,7 @@
 
 	/*
 	 * (non-Javadoc)
-	 * 
+	 *
 	 * @see org.apache.commons.vfs.provider.AbstractFileObject#doListChildren()
 	 */
 	protected String[] doListChildren() throws Exception
@@ -83,7 +83,7 @@
 
 	/*
 	 * (non-Javadoc)
-	 * 
+	 *
 	 * @see org.apache.commons.vfs.provider.AbstractFileObject#doGetContentSize()
 	 */
 	protected long doGetContentSize() throws Exception
@@ -93,7 +93,7 @@
 
 	/*
 	 * (non-Javadoc)
-	 * 
+	 *
 	 * @see org.apache.commons.vfs.provider.AbstractFileObject#doGetInputStream()
 	 */
 	protected InputStream doGetInputStream() throws Exception
@@ -103,7 +103,7 @@
 
 	/*
 	 * (non-Javadoc)
-	 * 
+	 *
 	 * @see org.apache.commons.vfs.provider.AbstractFileObject#doGetOutputStream(boolean)
 	 */
 	protected OutputStream doGetOutputStream(boolean bAppend) throws Exception
@@ -117,7 +117,7 @@
 
 	/*
 	 * (non-Javadoc)
-	 * 
+	 *
 	 * @see org.apache.commons.vfs.provider.AbstractFileObject#doDelete()
 	 */
 	protected void doDelete() throws Exception
@@ -127,7 +127,7 @@
 
 	/*
 	 * (non-Javadoc)
-	 * 
+	 *
 	 * @see org.apache.commons.vfs.provider.AbstractFileObject#doGetLastModifiedTime()
 	 */
 	protected long doGetLastModifiedTime() throws Exception
@@ -137,17 +137,18 @@
 
 	/*
 	 * (non-Javadoc)
-	 * 
+	 *
 	 * @see org.apache.commons.vfs.provider.AbstractFileObject#doSetLastModifiedTime(long)
 	 */
-	protected void doSetLastModifiedTime(long modtime) throws Exception
+	protected boolean doSetLastModTime(long modtime) throws Exception
 	{
 		data.setLastModified(modtime);
+		return true;
 	}
 
 	/*
 	 * (non-Javadoc)
-	 * 
+	 *
 	 * @see org.apache.commons.vfs.provider.AbstractFileObject#doCreateFolder()
 	 */
 	protected void doCreateFolder() throws Exception
@@ -158,7 +159,7 @@
 
 	/*
 	 * (non-Javadoc)
-	 * 
+	 *
 	 * @see org.apache.commons.vfs.provider.AbstractFileObject#doRename(org.apache.commons.vfs.FileObject)
 	 */
 	protected void doRename(FileObject newfile) throws Exception
@@ -168,7 +169,7 @@
 
 	/*
 	 * (non-Javadoc)
-	 * 
+	 *
 	 * @see org.apache.commons.vfs.provider.AbstractFileObject#doGetRandomAccessContent(org.apache.commons.vfs.util.RandomAccessMode)
 	 */
 	protected RandomAccessContent doGetRandomAccessContent(RandomAccessMode mode)
@@ -179,7 +180,7 @@
 
 	/*
 	 * (non-Javadoc)
-	 * 
+	 *
 	 * @see org.apache.commons.vfs.provider.AbstractFileObject#doAttach()
 	 */
 	protected void doAttach() throws Exception
@@ -206,7 +207,7 @@
 
 	/*
 	 * (non-Javadoc)
-	 * 
+	 *
 	 * @see org.apache.commons.vfs.provider.AbstractFileObject#injectType(org.apache.commons.vfs.FileType)
 	 */
 	protected void injectType(FileType fileType)
@@ -217,7 +218,7 @@
 
 	/*
 	 * (non-Javadoc)
-	 * 
+	 *
 	 * @see org.apache.commons.vfs.provider.AbstractFileObject#endOutput()
 	 */
 	protected void endOutput() throws Exception

Added: jakarta/commons/proper/vfs/trunk/examples/src/main/java/org/apache/commons/vfs/example/ChangeLastModificationTime.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/vfs/trunk/examples/src/main/java/org/apache/commons/vfs/example/ChangeLastModificationTime.java?view=auto&rev=488989
==============================================================================
--- jakarta/commons/proper/vfs/trunk/examples/src/main/java/org/apache/commons/vfs/example/ChangeLastModificationTime.java (added)
+++ jakarta/commons/proper/vfs/trunk/examples/src/main/java/org/apache/commons/vfs/example/ChangeLastModificationTime.java Wed Dec 20 01:14:53 2006
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.vfs.example;
+
+import org.apache.commons.vfs.FileSystemManager;
+import org.apache.commons.vfs.VFS;
+import org.apache.commons.vfs.FileObject;
+import org.apache.commons.vfs.FileType;
+import org.apache.commons.vfs.FileSystemException;
+
+import java.text.DateFormat;
+import java.util.Date;
+
+/**
+ * Simply changed the last modification time of the given file
+ *
+ * @author imario@apache.org
+ */
+public class ChangeLastModificationTime
+{
+    public static void main(String[] args) throws Exception
+	{
+        if (args.length == 0)
+        {
+            System.err.println("Please pass the name of a file as parameter.");
+            return;
+        }
+
+		FileObject fo = VFS.getManager().resolveFile(args[0]);
+		long setTo = System.currentTimeMillis();
+		System.err.println("set to: " + setTo);
+		fo.getContent().setLastModifiedTime(setTo);
+		System.err.println("after set: " + fo.getContent().getLastModifiedTime());
+    }
+}

Propchange: jakarta/commons/proper/vfs/trunk/examples/src/main/java/org/apache/commons/vfs/example/ChangeLastModificationTime.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/proper/vfs/trunk/examples/src/main/java/org/apache/commons/vfs/example/ChangeLastModificationTime.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/commons/proper/vfs/trunk/examples/src/main/java/org/apache/commons/vfs/example/ChangeLastModificationTime.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org