@ -67,6 +67,7 @@ import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId ;
import org.eclipse.jgit.lib.ObjectId ;
import org.eclipse.jgit.lib.ObjectInserter ;
import org.eclipse.jgit.lib.ObjectInserter ;
import org.eclipse.jgit.storage.file.LockFile ;
import org.eclipse.jgit.storage.file.LockFile ;
import org.eclipse.jgit.util.FS ;
import org.eclipse.jgit.util.IO ;
import org.eclipse.jgit.util.IO ;
import org.eclipse.jgit.util.MutableInteger ;
import org.eclipse.jgit.util.MutableInteger ;
import org.eclipse.jgit.util.NB ;
import org.eclipse.jgit.util.NB ;
@ -129,7 +130,7 @@ public class DirCache {
* memory ) .
* memory ) .
* /
* /
public static DirCache newInCore ( ) {
public static DirCache newInCore ( ) {
return new DirCache ( null ) ;
return new DirCache ( null , null ) ;
}
}
/ * *
/ * *
@ -141,6 +142,9 @@ public class DirCache {
*
*
* @param indexLocation
* @param indexLocation
* location of the index file on disk .
* location of the index file on disk .
* @param fs
* the file system abstraction which will be necessary to perform
* certain file system operations .
* @return a cache representing the contents of the specified index file ( if
* @return a cache representing the contents of the specified index file ( if
* it exists ) or an empty cache if the file does not exist .
* it exists ) or an empty cache if the file does not exist .
* @throws IOException
* @throws IOException
@ -149,9 +153,9 @@ public class DirCache {
* the index file is using a format or extension that this
* the index file is using a format or extension that this
* library does not support .
* library does not support .
* /
* /
public static DirCache read ( final File indexLocation )
public static DirCache read ( final File indexLocation , final FS fs )
throws CorruptObjectException , IOException {
throws CorruptObjectException , IOException {
final DirCache c = new DirCache ( indexLocation ) ;
final DirCache c = new DirCache ( indexLocation , fs ) ;
c . read ( ) ;
c . read ( ) ;
return c ;
return c ;
}
}
@ -161,11 +165,14 @@ public class DirCache {
* < p >
* < p >
* The new index will be locked and then read before it is returned to the
* The new index will be locked and then read before it is returned to the
* caller . Read failures are reported as exceptions and therefore prevent
* caller . Read failures are reported as exceptions and therefore prevent
* the method from returning a partially populated index . On read failure ,
* the method from returning a partially populated index . On read failure ,
* the lock is released .
* the lock is released .
*
*
* @param indexLocation
* @param indexLocation
* location of the index file on disk .
* location of the index file on disk .
* @param fs
* the file system abstraction which will be necessary to perform
* certain file system operations .
* @return a cache representing the contents of the specified index file ( if
* @return a cache representing the contents of the specified index file ( if
* it exists ) or an empty cache if the file does not exist .
* it exists ) or an empty cache if the file does not exist .
* @throws IOException
* @throws IOException
@ -175,9 +182,9 @@ public class DirCache {
* the index file is using a format or extension that this
* the index file is using a format or extension that this
* library does not support .
* library does not support .
* /
* /
public static DirCache lock ( final File indexLocation )
public static DirCache lock ( final File indexLocation , final FS fs )
throws CorruptObjectException , IOException {
throws CorruptObjectException , IOException {
final DirCache c = new DirCache ( indexLocation ) ;
final DirCache c = new DirCache ( indexLocation , fs ) ;
if ( ! c . lock ( ) )
if ( ! c . lock ( ) )
throw new IOException ( MessageFormat . format ( JGitText . get ( ) . cannotLock , indexLocation ) ) ;
throw new IOException ( MessageFormat . format ( JGitText . get ( ) . cannotLock , indexLocation ) ) ;
@ -215,6 +222,9 @@ public class DirCache {
/** Our active lock (if we hold it); null if we don't have it locked. */
/** Our active lock (if we hold it); null if we don't have it locked. */
private LockFile myLock ;
private LockFile myLock ;
/** file system abstraction **/
private final FS fs ;
/ * *
/ * *
* Create a new in - core index representation .
* Create a new in - core index representation .
* < p >
* < p >
@ -223,9 +233,13 @@ public class DirCache {
*
*
* @param indexLocation
* @param indexLocation
* location of the index file on disk .
* location of the index file on disk .
* @param fs
* the file system abstraction which will be necessary to perform
* certain file system operations .
* /
* /
public DirCache ( final File indexLocation ) {
public DirCache ( final File indexLocation , final FS fs ) {
liveFile = indexLocation ;
liveFile = indexLocation ;
this . fs = fs ;
clear ( ) ;
clear ( ) ;
}
}
@ -429,7 +443,7 @@ public class DirCache {
public boolean lock ( ) throws IOException {
public boolean lock ( ) throws IOException {
if ( liveFile = = null )
if ( liveFile = = null )
throw new IOException ( JGitText . get ( ) . dirCacheDoesNotHaveABackingFile ) ;
throw new IOException ( JGitText . get ( ) . dirCacheDoesNotHaveABackingFile ) ;
final LockFile tmp = new LockFile ( liveFile ) ;
final LockFile tmp = new LockFile ( liveFile , fs ) ;
if ( tmp . lock ( ) ) {
if ( tmp . lock ( ) ) {
tmp . setNeedStatInformation ( true ) ;
tmp . setNeedStatInformation ( true ) ;
myLock = tmp ;
myLock = tmp ;