本文整理汇总了C#中Sharpen.FilePath.GetName方法的典型用法代码示例。如果您正苦于以下问题:C# FilePath.GetName方法的具体用法?C# FilePath.GetName怎么用?C# FilePath.GetName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sharpen.FilePath
的用法示例。
在下文中一共展示了FilePath.GetName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FailingPathsShouldNotResultInOKReturnValue
public virtual void FailingPathsShouldNotResultInOKReturnValue()
{
FilePath folder1 = new FilePath(db.WorkTree, "folder1");
FileUtils.Mkdir(folder1);
FilePath file = new FilePath(folder1, "file1.txt");
Write(file, "folder1--file1.txt");
file = new FilePath(folder1, "file2.txt");
Write(file, "folder1--file2.txt");
Git git = new Git(db);
git.Add().AddFilepattern(folder1.GetName()).Call();
RevCommit @base = git.Commit().SetMessage("adding folder").Call();
RecursiveDelete(folder1);
git.Rm().AddFilepattern("folder1/file1.txt").AddFilepattern("folder1/file2.txt").
Call();
RevCommit other = git.Commit().SetMessage("removing folders on 'other'").Call();
git.Checkout().SetName(@base.Name).Call();
file = new FilePath(db.WorkTree, "unrelated.txt");
Write(file, "unrelated");
git.Add().AddFilepattern("unrelated").Call();
RevCommit head = git.Commit().SetMessage("Adding another file").Call();
// Untracked file to cause failing path for delete() of folder1
file = new FilePath(folder1, "file3.txt");
Write(file, "folder1--file3.txt");
ResolveMerger merger = new ResolveMerger(db, false);
merger.SetCommitNames(new string[] { "BASE", "HEAD", "other" });
merger.SetWorkingTreeIterator(new FileTreeIterator(db));
bool ok = merger.Merge(head.Id, other.Id);
NUnit.Framework.Assert.IsFalse(merger.GetFailingPaths().IsEmpty());
NUnit.Framework.Assert.IsFalse(ok);
}
示例2: PackLock
/// <summary>Create a new lock for a pack file.</summary>
/// <remarks>Create a new lock for a pack file.</remarks>
/// <param name="packFile">location of the <code>pack-*.pack</code> file.</param>
/// <param name="fs">the filesystem abstraction used by the repository.</param>
public PackLock(FilePath packFile, FS fs)
{
FilePath p = packFile.GetParentFile();
string n = packFile.GetName();
keepFile = new FilePath(p, Sharpen.Runtime.Substring(n, 0, n.Length - 5) + ".keep"
);
this.fs = fs;
}
示例3: FileBody
/// <since>4.1</since>
public FileBody(FilePath file, string filename, string mimeType, string charset) :
base(mimeType)
{
if (file == null)
{
throw new ArgumentException("File may not be null");
}
this.file = file;
if (filename != null)
{
this.filename = filename;
}
else
{
this.filename = file.GetName();
}
this.charset = charset;
}
示例4: Accept
public override bool Accept(FilePath f)
{
if (f.IsDirectory())
{
return true;
}
string name = f.GetName();
int i = name.LastIndexOf('.');
if (i > 0 && i < name.Length - 1)
{
string ext = Sharpen.Runtime.Substring(name, i + 1).ToLower();
if (ext.Equals("js"))
{
return true;
}
}
return false;
}
示例5: OpenPack
/// <summary>Add a single existing pack to the list of available pack files.</summary>
/// <remarks>Add a single existing pack to the list of available pack files.</remarks>
/// <param name="pack">path of the pack file to open.</param>
/// <param name="idx">path of the corresponding index file.</param>
/// <returns>the pack that was opened and added to the database.</returns>
/// <exception cref="System.IO.IOException">
/// index file could not be opened, read, or is not recognized as
/// a Git pack file index.
/// </exception>
internal override PackFile OpenPack(FilePath pack, FilePath idx)
{
string p = pack.GetName();
string i = idx.GetName();
if (p.Length != 50 || !p.StartsWith("pack-") || !p.EndsWith(".pack"))
{
throw new IOException(MessageFormat.Format(JGitText.Get().notAValidPack, pack));
}
if (i.Length != 49 || !i.StartsWith("pack-") || !i.EndsWith(".idx"))
{
throw new IOException(MessageFormat.Format(JGitText.Get().notAValidPack, idx));
}
if (!Sharpen.Runtime.Substring(p, 0, 45).Equals(Sharpen.Runtime.Substring(i, 0, 45
)))
{
throw new IOException(MessageFormat.Format(JGitText.Get().packDoesNotMatchIndex,
pack));
}
PackFile res = new PackFile(idx, pack);
InsertPack(res);
return res;
}
示例6: CheckoutEntry
/// <summary>
/// Updates the file in the working tree with content and mode from an entry
/// in the index.
/// </summary>
/// <remarks>
/// Updates the file in the working tree with content and mode from an entry
/// in the index. The new content is first written to a new temporary file in
/// the same directory as the real file. Then that new file is renamed to the
/// final filename.
/// <p>
/// TODO: this method works directly on File IO, we may need another
/// abstraction (like WorkingTreeIterator). This way we could tell e.g.
/// Eclipse that Files in the workspace got changed
/// </p>
/// </remarks>
/// <param name="repo"></param>
/// <param name="f">
/// the file to be modified. The parent directory for this file
/// has to exist already
/// </param>
/// <param name="entry">the entry containing new mode and content</param>
/// <param name="or">object reader to use for checkout</param>
/// <exception cref="System.IO.IOException">System.IO.IOException</exception>
public static void CheckoutEntry(Repository repo, FilePath f, DirCacheEntry entry
, ObjectReader or)
{
ObjectLoader ol = or.Open(entry.GetObjectId());
FilePath parentDir = f.GetParentFile();
FilePath tmpFile = FilePath.CreateTempFile("._" + f.GetName(), null, parentDir);
WorkingTreeOptions opt = repo.GetConfig().Get(WorkingTreeOptions.KEY);
FileOutputStream rawChannel = new FileOutputStream(tmpFile);
OutputStream channel;
if (opt.GetAutoCRLF() == CoreConfig.AutoCRLF.TRUE)
{
channel = new AutoCRLFOutputStream(rawChannel);
}
else
{
channel = rawChannel;
}
try
{
ol.CopyTo(channel);
}
finally
{
channel.Close();
}
FS fs = repo.FileSystem;
if (opt.IsFileMode() && fs.SupportsExecute())
{
if (FileMode.EXECUTABLE_FILE.Equals(entry.RawMode))
{
if (!fs.CanExecute(tmpFile))
{
fs.SetExecute(tmpFile, true);
}
}
else
{
if (fs.CanExecute(tmpFile))
{
fs.SetExecute(tmpFile, false);
}
}
}
if (!tmpFile.RenameTo(f))
{
// tried to rename which failed. Let' delete the target file and try
// again
FileUtils.Delete(f);
if (!tmpFile.RenameTo(f))
{
throw new IOException(MessageFormat.Format(JGitText.Get().couldNotWriteFile, tmpFile
.GetPath(), f.GetPath()));
}
}
entry.LastModified = f.LastModified();
if (opt.GetAutoCRLF() != CoreConfig.AutoCRLF.FALSE)
{
entry.SetLength(f.Length());
}
else
{
// AutoCRLF wants on-disk-size
entry.SetLength((int)ol.GetSize());
}
}
示例7: LockFile
/// <summary>Create a new lock for any file.</summary>
/// <remarks>Create a new lock for any file.</remarks>
/// <param name="f">the file that will be locked.</param>
/// <param name="fs">
/// the file system abstraction which will be necessary to perform
/// certain file system operations.
/// </param>
public LockFile(FilePath f, FS fs)
{
@ref = f;
lck = new FilePath(@ref.GetParentFile(), @ref.GetName() + SUFFIX);
this.fs = fs;
}
示例8: Accept
public bool Accept(FilePath f)
{
return f.GetName().EndsWith(JsTestsTest.jstestsExtension);
}
示例9: TestMergeRemovingFoldersWithoutFastForward
public virtual void TestMergeRemovingFoldersWithoutFastForward()
{
FilePath folder1 = new FilePath(db.WorkTree, "folder1");
FilePath folder2 = new FilePath(db.WorkTree, "folder2");
FileUtils.Mkdir(folder1);
FileUtils.Mkdir(folder2);
FilePath file = new FilePath(folder1, "file1.txt");
Write(file, "folder1--file1.txt");
file = new FilePath(folder1, "file2.txt");
Write(file, "folder1--file2.txt");
file = new FilePath(folder2, "file1.txt");
Write(file, "folder--file1.txt");
file = new FilePath(folder2, "file2.txt");
Write(file, "folder2--file2.txt");
Git git = new Git(db);
git.Add().AddFilepattern(folder1.GetName()).AddFilepattern(folder2.GetName()).Call
();
RevCommit @base = git.Commit().SetMessage("adding folders").Call();
RecursiveDelete(folder1);
RecursiveDelete(folder2);
git.Rm().AddFilepattern("folder1/file1.txt").AddFilepattern("folder1/file2.txt").
AddFilepattern("folder2/file1.txt").AddFilepattern("folder2/file2.txt").Call();
RevCommit other = git.Commit().SetMessage("removing folders on 'branch'").Call();
git.Checkout().SetName(@base.Name).Call();
file = new FilePath(folder2, "file3.txt");
Write(file, "folder2--file3.txt");
git.Add().AddFilepattern(folder2.GetName()).Call();
git.Commit().SetMessage("adding another file").Call();
MergeCommandResult result = git.Merge().Include(other.Id).SetStrategy(MergeStrategy
.RESOLVE).Call();
NUnit.Framework.Assert.AreEqual(MergeStatus.MERGED, result.GetMergeStatus());
NUnit.Framework.Assert.IsFalse(folder1.Exists());
}
示例10: VisitEntry
/// <exception cref="System.IO.IOException"></exception>
public override void VisitEntry(TreeEntry m, GitIndex.Entry i, FilePath f)
{
// TODO remove this once we support submodules
if (f.GetName().Equals(".gitmodules"))
{
throw new NotSupportedException(JGitText.Get().submodulesNotSupported);
}
if (m == null)
{
this._enclosing.index.Remove(this._enclosing.root, f);
return;
}
bool needsCheckout = false;
if (i == null)
{
needsCheckout = true;
}
else
{
if (i.GetObjectId().Equals(m.GetId()))
{
if (i.IsModified(this._enclosing.root, true))
{
needsCheckout = true;
}
}
else
{
needsCheckout = true;
}
}
if (needsCheckout)
{
GitIndex.Entry newEntry = this._enclosing.index.AddEntry(m);
this._enclosing.index.CheckoutEntry(this._enclosing.root, newEntry);
}
}
示例11: BaseName
private static string BaseName(FilePath tmpPack)
{
string name = tmpPack.GetName();
return Sharpen.Runtime.Substring(name, 0, name.LastIndexOf('.'));
}
示例12: IndexPack
/// <summary>Create a new pack indexer utility.</summary>
/// <remarks>Create a new pack indexer utility.</remarks>
/// <param name="db"></param>
/// <param name="src">
/// stream to read the pack data from. If the stream is buffered
/// use
/// <see cref="BUFFER_SIZE">BUFFER_SIZE</see>
/// as the buffer size for the stream.
/// </param>
/// <param name="dstBase"></param>
/// <exception cref="System.IO.IOException">the output packfile could not be created.
/// </exception>
public IndexPack(Repository db, InputStream src, FilePath dstBase)
{
repo = db;
objectDatabase = db.ObjectDatabase.NewCachedDatabase();
@in = src;
inflater = new IndexPack.InflaterStream(this);
readCurs = objectDatabase.NewReader();
buf = new byte[BUFFER_SIZE];
readBuffer = new byte[BUFFER_SIZE];
objectDigest = Constants.NewMessageDigest();
tempObjectId = new MutableObjectId();
packDigest = Constants.NewMessageDigest();
if (dstBase != null)
{
FilePath dir = dstBase.GetParentFile();
string nam = dstBase.GetName();
dstPack = new FilePath(dir, nam + ".pack");
dstIdx = new FilePath(dir, nam + ".idx");
packOut = new RandomAccessFile(dstPack, "rw");
packOut.SetLength(0);
}
else
{
dstPack = null;
dstIdx = null;
}
}
示例13: SingleDoctest
// move "@Parameters" to this method to test a single doctest
/// <exception cref="System.IO.IOException"></exception>
public static ICollection<object[]> SingleDoctest()
{
IList<object[]> result = new List<object[]>();
FilePath f = new FilePath(baseDirectory, "Counter.doctest");
string contents = LoadFile(f);
result.Add(new object[] { f.GetName(), contents, -1 });
return result;
}
示例14: Accept
public bool Accept(FilePath f)
{
return f.GetName().EndsWith(Rhino.Tests.DoctestsTest.doctestsExtension);
}
示例15: GetBytesFromFile
/// <exception cref="System.IO.IOException"></exception>
private static byte[] GetBytesFromFile(FilePath file)
{
InputStream @is = new FileInputStream(file);
// Get the size of the file
long length = file.Length();
// Create the byte array to hold the data
byte[] bytes = new byte[(int)length];
// Read in the bytes
int offset = 0;
int numRead = 0;
while (offset < bytes.Length && (numRead = @is.Read(bytes, offset, bytes.Length -
offset)) >= 0)
{
offset += numRead;
}
// Ensure all the bytes have been read in
if (offset < bytes.Length)
{
throw new IOException("Could not completely read file " + file.GetName());
}
// Close the input stream and return bytes
@is.Close();
return bytes;
}