本文整理汇总了C#中Sharpen.FilePath.SetReadOnly方法的典型用法代码示例。如果您正苦于以下问题:C# FilePath.SetReadOnly方法的具体用法?C# FilePath.SetReadOnly怎么用?C# FilePath.SetReadOnly使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sharpen.FilePath
的用法示例。
在下文中一共展示了FilePath.SetReadOnly方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FileFor
/// <exception cref="System.IO.IOException"></exception>
internal override FileObjectDatabase.InsertLooseObjectResult InsertUnpackedObject
(FilePath tmp, ObjectId id, bool createDuplicate)
{
// If the object is already in the repository, remove temporary file.
//
if (unpackedObjectCache.IsUnpacked(id))
{
FileUtils.Delete(tmp);
return FileObjectDatabase.InsertLooseObjectResult.EXISTS_LOOSE;
}
if (!createDuplicate && Has(id))
{
FileUtils.Delete(tmp);
return FileObjectDatabase.InsertLooseObjectResult.EXISTS_PACKED;
}
tmp.SetReadOnly();
FilePath dst = FileFor(id);
if (dst.Exists())
{
// We want to be extra careful and avoid replacing an object
// that already exists. We can't be sure renameTo() would
// fail on all platforms if dst exists, so we check first.
//
FileUtils.Delete(tmp);
return FileObjectDatabase.InsertLooseObjectResult.EXISTS_LOOSE;
}
if (tmp.RenameTo(dst))
{
unpackedObjectCache.Add(id);
return FileObjectDatabase.InsertLooseObjectResult.INSERTED;
}
// Maybe the directory doesn't exist yet as the object
// directories are always lazily created. Note that we
// try the rename first as the directory likely does exist.
//
dst.GetParentFile().Mkdir();
if (tmp.RenameTo(dst))
{
unpackedObjectCache.Add(id);
return FileObjectDatabase.InsertLooseObjectResult.INSERTED;
}
if (!createDuplicate && Has(id))
{
FileUtils.Delete(tmp);
return FileObjectDatabase.InsertLooseObjectResult.EXISTS_PACKED;
}
// The object failed to be renamed into its proper
// location and it doesn't exist in the repository
// either. We really don't know what went wrong, so
// fail.
//
FileUtils.Delete(tmp);
return FileObjectDatabase.InsertLooseObjectResult.FAILURE;
}
示例2: Parse
/// <exception cref="System.IO.IOException"></exception>
public override PackLock Parse(ProgressMonitor receiving, ProgressMonitor resolving
)
{
tmpPack = FilePath.CreateTempFile("incoming_", ".pack", db.GetDirectory());
tmpIdx = new FilePath(db.GetDirectory(), BaseName(tmpPack) + ".idx");
try
{
@out = new RandomAccessFile(tmpPack, "rw");
base.Parse(receiving, resolving);
@out.Seek(packEnd);
@out.Write(packHash);
@out.GetChannel().Force(true);
@out.Close();
WriteIdx();
tmpPack.SetReadOnly();
tmpIdx.SetReadOnly();
return RenameAndOpenPack(GetLockMessage());
}
finally
{
if (def != null)
{
def.Finish();
}
try
{
if (@out != null && @out.GetChannel().IsOpen())
{
@out.Close();
}
}
catch (IOException)
{
}
// Ignored. We want to delete the file.
CleanupTemporaryFiles();
}
}