jackrabbit-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Thomas Mueller (JIRA)" <j...@apache.org>
Subject [jira] Commented: (JCR-2872) DataStore: changing the modified date fails if the file is open for reading (Windows only)
Date Tue, 01 Feb 2011 15:26:29 GMT

    [ https://issues.apache.org/jira/browse/JCR-2872?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12989243#comment-12989243
] 

Thomas Mueller commented on JCR-2872:
-------------------------------------

Another option (also somewhat ugly) is to create / change the modified date of a specially
named marker file "<identifier>.mod" - so while changing the modified date of the original
file is not possible, at least it's possible to change the modified date of this marker file
(which has length 0). Before deleting data store files, the marker file needs to be checked
of course.

> DataStore: changing the modified date fails if the file is open for reading (Windows
only)
> ------------------------------------------------------------------------------------------
>
>                 Key: JCR-2872
>                 URL: https://issues.apache.org/jira/browse/JCR-2872
>             Project: Jackrabbit Content Repository
>          Issue Type: Bug
>          Components: jackrabbit-core
>         Environment: Windows
>            Reporter: Thomas Mueller
>            Assignee: Thomas Mueller
>
> If the file is open for reading, Windows doesn't allow to change the last modified time
using File.setLastModified():
> org.apache.jackrabbit.core.data.DataStoreException: Failed to update record
> modified date: 2ac72495fd1e270777821b8a872903c79c84a8d9
>         at org.apache.jackrabbit.core.data.FileDataStore.addRecord(FileDataStore.java:250)
>         at org.apache.jackrabbit.core.value.BLOBInDataStore.getInstance(BLOBInDataStore.java:119)
>         at org.apache.jackrabbit.core.value.InternalValue.getBLOBFileValue(InternalValue.java:619)
>         at org.apache.jackrabbit.core.value.InternalValue.create(InternalValue.java:369)
>         at org.apache.jackrabbit.core.value.InternalValueFactory.create(InternalValueFactory.java:94)
>         at org.apache.jackrabbit.core.value.ValueFactoryImpl.createBinary(ValueFactoryImpl.java:74)
> Test case and possible workaround:
> import java.io.File;
> import java.io.FileInputStream;
> import java.io.RandomAccessFile;
> public class Test {
>     public static void main(String... args) throws Exception {
>         String name = "test.txt";
>         File test = new File(name);
>         RandomAccessFile r = new RandomAccessFile(name, "rw");
>         r.write(0);
>         r.close();
>         long mod = test.lastModified();
>         Thread.sleep(3000);
>         FileInputStream in = new FileInputStream(name);
>         if (!test.setLastModified(test.lastModified()+1)) {
>         	if (!test.canWrite()) {
>         		System.out.println("Can't write to " + name);
>         	} else {
>             	System.out.println("canWrite ok");
>             	r = new RandomAccessFile(name, "rw");
>             	int old = r.read();
>             	r.seek(0);
>             	r.write(old);
>             	r.close();
>         	}
>         } else {
>         	System.out.println("setLastModified ok");
>         }
>         System.out.println("Modified old: " + mod);
>         System.out.println("Modified now: " + test.lastModified());
>         in.close();
>         System.out.println("input closed");
>         if (!test.setLastModified(test.lastModified()+1)) {
>         	if (!test.canWrite()) {
>         		System.out.println("Can't write to " + name);
>         	} else {
>             	System.out.println("canWrite ok");
>         	}
>         } else {
>         	System.out.println("setLastModified ok");
>         }
>         new File(name).delete();
>     }
> }

-- 
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Mime
View raw message