/// <summary>
/// Check if an entry's content is different from the cache,
///
/// File status information is used and status is same we
/// consider the file identical to the state in the working
/// directory. Native git uses more stat fields than we
/// have accessible in Java.
/// </summary>
/// <param name="wd"> working directory to compare content with </param>
/// <param name="forceContentCheck">
/// True if the actual file content should be checked if modification time differs.
/// </param>
/// <returns> true if content is most likely different. </returns>
public bool IsModified(DirectoryInfo wd, bool forceContentCheck)
{
if (isAssumedValid())
{
return(false);
}
if (isUpdateNeeded())
{
return(true);
}
FileInfo file = getFile(wd);
if (!file.Exists)
{
return(true);
}
// JDK1.6 has file.canExecute
// if (file.canExecute() != FileMode.EXECUTABLE_FILE.equals(mode))
// return true;
int exebits = FileMode.ExecutableFile.Bits ^ FileMode.RegularFile.Bits;
if (ConfigFileMode && FileMode.ExecutableFile.Equals(Mode))
{
if (!FileCanExecute(file) && FileHasExecute())
{
return(true);
}
}
else
{
if (FileMode.RegularFile.Equals(Mode & ~exebits))
{
if (!File.Exists(file.FullName) || ConfigFileMode && FileCanExecute(file) && FileHasExecute())
{
return(true);
}
}
else
{
if (FileMode.Symlink.Equals(Mode))
{
return(true);
}
if (FileMode.Tree.Equals(Mode))
{
if (!Directory.Exists(file.FullName))
{
return(true);
}
}
else
{
Console.WriteLine("Does not handle mode " + Mode + " (" + file + ")");
return(true);
}
}
}
if (file.Length != _size)
{
return(true);
}
// Git under windows only stores seconds so we round the timestamp
// Java gives us if it looks like the timestamp in index is seconds
// only. Otherwise we compare the timestamp at millisecond prevision.
long javamtime = Mtime / 1000000L;
long lastm = file.lastModified();
if (javamtime % 1000 == 0)
{
lastm = lastm - lastm % 1000;
}
if (lastm != javamtime)
{
if (!forceContentCheck)
{
return(true);
}
try
{
using (Stream @is = new FileStream(file.FullName, System.IO.FileMode.Open, FileAccess.Read))
{
try
{
var objectWriter = new ObjectWriter(Repository);
ObjectId newId = objectWriter.ComputeBlobSha1(file.Length, @is);
bool ret = !newId.Equals(ObjectId);
return(ret);
}
catch (IOException e)
{
e.printStackTrace();
}
finally
{
try
{
@is.Close();
}
catch (IOException e)
{
// can't happen, but if it does we ignore it
e.printStackTrace();
}
}
}
}
catch (FileNotFoundException e)
{
// should not happen because we already checked this
e.printStackTrace();
throw;
}
}
return(false);
}