private static void RunFileIfExists(Context cx, Scriptable global, FilePath f) { if (f.IsFile()) { Main.ProcessFileNoThrow(cx, global, f.GetPath()); } }
public virtual void Test001_Initalize() { FilePath gitdir = new FilePath(trash, Constants.DOT_GIT); FilePath hooks = new FilePath(gitdir, "hooks"); FilePath objects = new FilePath(gitdir, "objects"); FilePath objects_pack = new FilePath(objects, "pack"); FilePath objects_info = new FilePath(objects, "info"); FilePath refs = new FilePath(gitdir, "refs"); FilePath refs_heads = new FilePath(refs, "heads"); FilePath refs_tags = new FilePath(refs, "tags"); FilePath HEAD = new FilePath(gitdir, "HEAD"); NUnit.Framework.Assert.IsTrue(trash.IsDirectory(), "Exists " + trash); NUnit.Framework.Assert.IsTrue(hooks.IsDirectory(), "Exists " + hooks); NUnit.Framework.Assert.IsTrue(objects.IsDirectory(), "Exists " + objects); NUnit.Framework.Assert.IsTrue(objects_pack.IsDirectory(), "Exists " + objects_pack ); NUnit.Framework.Assert.IsTrue(objects_info.IsDirectory(), "Exists " + objects_info ); NUnit.Framework.Assert.AreEqual(2L, objects.ListFiles().Length); NUnit.Framework.Assert.IsTrue(refs.IsDirectory(), "Exists " + refs); NUnit.Framework.Assert.IsTrue(refs_heads.IsDirectory(), "Exists " + refs_heads); NUnit.Framework.Assert.IsTrue(refs_tags.IsDirectory(), "Exists " + refs_tags); NUnit.Framework.Assert.IsTrue(HEAD.IsFile(), "Exists " + HEAD); NUnit.Framework.Assert.AreEqual(23, HEAD.Length()); }
public virtual void TestEmptyIfRootIsFile() { FilePath r = new FilePath(trash, paths[0]); NUnit.Framework.Assert.IsTrue(r.IsFile()); FileTreeIterator fti = new FileTreeIterator(r, db.FileSystem, ((FileBasedConfig)db .GetConfig()).Get(WorkingTreeOptions.KEY)); NUnit.Framework.Assert.IsTrue(fti.First); NUnit.Framework.Assert.IsTrue(fti.Eof); }
private static void AddTests(TestSuite suite, FilePath testDir, string name) { FilePath programFile = new FilePath(testDir, "program.js"); if (programFile.IsFile()) { suite.AddTest(CreateTest(testDir, name)); } else { FilePath[] files = testDir.ListFiles(); foreach (FilePath file in files) { if (file.IsDirectory()) { AddTests(suite, file, name + "/" + file.GetName()); } } } }
public virtual void Test002_WriteEmptyTree2() { // File shouldn't exist as it is in a test pack. // ObjectId treeId = InsertTree(new TreeFormatter()); NUnit.Framework.Assert.AreEqual("4b825dc642cb6eb9a060e54bf8d69288fbee4904", treeId .Name); FilePath o = new FilePath(new FilePath(new FilePath(db.Directory, "objects"), "4b" ), "825dc642cb6eb9a060e54bf8d69288fbee4904"); NUnit.Framework.Assert.IsFalse(o.IsFile(), "Exists " + o); }
public virtual void Test002_WriteEmptyTree() { // One of our test packs contains the empty tree object. If the pack is // open when we create it we won't write the object file out as a loose // object (as it already exists in the pack). // Repository newdb = CreateBareRepository(); ObjectInserter oi = newdb.NewObjectInserter(); ObjectId treeId = oi.Insert(new TreeFormatter()); oi.Release(); NUnit.Framework.Assert.AreEqual("4b825dc642cb6eb9a060e54bf8d69288fbee4904", treeId .Name); FilePath o = new FilePath(new FilePath(new FilePath(newdb.Directory, "objects"), "4b"), "825dc642cb6eb9a060e54bf8d69288fbee4904"); NUnit.Framework.Assert.IsTrue(o.IsFile(), "Exists " + o); NUnit.Framework.Assert.IsTrue(!o.CanWrite(), "Read-only " + o); }
private string ReadSource(FilePath f) { string absPath = f.GetAbsolutePath(); if (!f.IsFile()) { AddError("msg.jsfile.not.found", absPath); return null; } try { return (string)SourceReader.ReadFileOrUrl(absPath, true, characterEncoding); } catch (FileNotFoundException) { AddError("msg.couldnt.open", absPath); } catch (IOException ioe) { AddFormatedError(ioe.ToString()); } return null; }
/// <exception cref="NGit.Errors.CorruptObjectException"></exception> /// <exception cref="System.IO.IOException"></exception> public virtual void AssertWorkDir(Dictionary<string, string> i) { TreeWalk walk = new TreeWalk(db); walk.Recursive = true; walk.AddTree(new FileTreeIterator(db)); string expectedValue; string path; int nrFiles = 0; FileTreeIterator ft; while (walk.Next()) { ft = walk.GetTree<FileTreeIterator>(0); path = ft.EntryPathString; expectedValue = i.Get(path); NUnit.Framework.Assert.IsNotNull(expectedValue, "found unexpected file for path " + path + " in workdir"); FilePath file = new FilePath(db.WorkTree, path); NUnit.Framework.Assert.IsTrue(file.Exists()); if (file.IsFile()) { FileInputStream @is = new FileInputStream(file); byte[] buffer = new byte[(int)file.Length()]; int offset = 0; int numRead = 0; while (offset < buffer.Length && (numRead = @is.Read(buffer, offset, buffer.Length - offset)) >= 0) { offset += numRead; } @is.Close(); CollectionAssert.AreEqual (buffer, Sharpen.Runtime.GetBytesForString(i.Get(path)), "unexpected content for path " + path + " in workDir. "); nrFiles++; } } NUnit.Framework.Assert.AreEqual(i.Count, nrFiles, "WorkDir has not the right size." ); }
/// <exception cref="System.IO.IOException"></exception> internal virtual void PrescanTwoTrees() { new IndexTreeWalker(index, head, merge, root, new _AbstractIndexTreeVisitor_267(this )).Walk(); // if there's a conflict, don't list it under // to-be-removed, since that messed up our next // section removed.RemoveAll(conflicts); foreach (string path in updated.Keys) { if (index.GetEntry(path) == null) { FilePath file = new FilePath(root, path); if (file.IsFile()) { conflicts.AddItem(path); } else { if (file.IsDirectory()) { CheckConflictsWithFile(file); } } } } conflicts.RemoveAll(removed); }
/// <exception cref="System.IO.IOException"></exception> public override void VisitEntry(TreeEntry m, GitIndex.Entry i, FilePath file) { if (m != null) { if (!file.IsFile()) { this._enclosing.CheckConflictsWithFile(file); } } else { if (file.Exists()) { this._enclosing.removed.AddItem(i.GetName()); this._enclosing.conflicts.Remove(i.GetName()); } } }
/// <exception cref="System.NotSupportedException"></exception> private Properties LoadProperties() { if (local.Directory != null) { FilePath propsFile = new FilePath(local.Directory, uri.GetUser()); if (propsFile.IsFile()) { return LoadPropertiesFile(propsFile); } } FilePath propsFile_1 = new FilePath(local.FileSystem.UserHome(), uri.GetUser()); if (propsFile_1.IsFile()) { return LoadPropertiesFile(propsFile_1); } Properties props = new Properties(); props.SetProperty("accesskey", uri.GetUser()); props.SetProperty("secretkey", uri.GetPass()); return props; }
private static void LoadIdentity(JSch sch, FilePath priv) { if (priv.IsFile()) { try { sch.AddIdentity(priv.GetAbsolutePath()); } catch (JSchException) { } } }
/// <exception cref="System.IO.IOException"></exception> public override ObjectLoader Open(string path, ObjectId id) { FilePath p = new FilePath(root, path); if (!p.IsFile()) { throw new FileNotFoundException(path); } return new _ObjectLoader_237(p); }
/// <summary> /// Calling this method establishes a module as being the main module of the /// program to which this require() instance belongs. /// </summary> /// <remarks> /// Calling this method establishes a module as being the main module of the /// program to which this require() instance belongs. The module will be /// loaded as if require()'d and its "module" property will be set as the /// "main" property of this require() instance. You have to call this method /// before the module has been loaded (that is, the call to this method must /// be the first to require the module and thus trigger its loading). Note /// that the main module will execute in its own scope and not in the global /// scope. Since all other modules see the global scope, executing the main /// module in the global scope would open it for tampering by other modules. /// </remarks> /// <param name="cx">the current context</param> /// <param name="mainModuleId">the ID of the main module</param> /// <returns>the "exports" property of the main module</returns> /// <exception cref="System.InvalidOperationException"> /// if the main module is already loaded when /// required, or if this require() instance already has a different main /// module set. /// </exception> public virtual Scriptable RequireMain(Context cx, string mainModuleId) { if (this.mainModuleId != null) { if (!this.mainModuleId.Equals(mainModuleId)) { throw new InvalidOperationException("Main module already set to " + this.mainModuleId); } return mainExports; } ModuleScript moduleScript; try { // try to get the module script to see if it is on the module path moduleScript = moduleScriptProvider.GetModuleScript(cx, mainModuleId, null, null, paths); } catch (Exception x) { throw; } catch (Exception x) { throw new Exception(x); } if (moduleScript != null) { mainExports = GetExportedModuleInterface(cx, mainModuleId, null, null, true); } else { if (!sandboxed) { Uri mainUri = null; // try to resolve to an absolute URI or file path try { mainUri = new Uri(mainModuleId); } catch (URISyntaxException) { } // fall through // if not an absolute uri resolve to a file path if (mainUri == null || !mainUri.IsAbsoluteUri) { FilePath file = new FilePath(mainModuleId); if (!file.IsFile()) { throw ScriptRuntime.ThrowError(cx, nativeScope, "Module \"" + mainModuleId + "\" not found."); } mainUri = file.ToURI(); } mainExports = GetExportedModuleInterface(cx, mainUri.ToString(), mainUri, null, true); } } this.mainModuleId = mainModuleId; return mainExports; }