Mkdir() public method

public Mkdir ( ) : bool
return bool
Ejemplo n.º 1
0
		public virtual void TestSameDiff()
		{
			Write(new FilePath(db.Directory.GetParent(), "test.txt"), "test");
			FilePath folder = new FilePath(db.Directory.GetParent(), "folder");
			folder.Mkdir();
			Write(new FilePath(folder, "folder.txt"), "\n\n\n\nfolder");
			Git git = new Git(db);
			git.Add().AddFilepattern(".").Call();
			git.Commit().SetMessage("Initial commit").Call();
			Write(new FilePath(folder, "folder.txt"), "\n\n\n\nfolder change");
			PatchIdDiffFormatter df = new PatchIdDiffFormatter();
			df.SetRepository(db);
			df.SetPathFilter(PathFilter.Create("folder"));
			DirCacheIterator oldTree = new DirCacheIterator(db.ReadDirCache());
			FileTreeIterator newTree = new FileTreeIterator(db);
			df.Format(oldTree, newTree);
			df.Flush();
			NUnit.Framework.Assert.AreEqual("08fca5ac531383eb1da8bf6b6f7cf44411281407", df.GetCalulatedPatchId
				().Name);
			Write(new FilePath(folder, "folder.txt"), "a\n\n\n\nfolder");
			git.Add().AddFilepattern(".").Call();
			git.Commit().SetMessage("Initial commit").Call();
			Write(new FilePath(folder, "folder.txt"), "a\n\n\n\nfolder change");
			df = new PatchIdDiffFormatter();
			df.SetRepository(db);
			df.SetPathFilter(PathFilter.Create("folder"));
			oldTree = new DirCacheIterator(db.ReadDirCache());
			newTree = new FileTreeIterator(db);
			df.Format(oldTree, newTree);
			df.Flush();
			NUnit.Framework.Assert.AreEqual("08fca5ac531383eb1da8bf6b6f7cf44411281407", df.GetCalulatedPatchId
				().Name);
		}
Ejemplo n.º 2
0
		/// <exception cref="System.Exception"></exception>
		public virtual void TestUpgradeOldDatabaseFiles()
		{
			string directoryName = "test-directory-" + Runtime.CurrentTimeMillis();
			string normalFilesDir = GetRootDirectory().GetAbsolutePath();
			string fakeFilesDir = string.Format("%s/%s", normalFilesDir, directoryName);
			FilePath directory = new FilePath(fakeFilesDir);
			if (!directory.Exists())
			{
				bool result = directory.Mkdir();
				if (!result)
				{
					throw new IOException("Unable to create directory " + directory);
				}
			}
			FilePath oldTouchDbFile = new FilePath(directory, string.Format("old%s", Manager.
				DatabaseSuffixOld));
			oldTouchDbFile.CreateNewFile();
			FilePath newCbLiteFile = new FilePath(directory, string.Format("new%s", Manager.DatabaseSuffix
				));
			newCbLiteFile.CreateNewFile();
			FilePath migratedOldFile = new FilePath(directory, string.Format("old%s", Manager
				.DatabaseSuffix));
			migratedOldFile.CreateNewFile();
			base.StopCBLite();
			manager = new Manager(new FilePath(GetRootDirectory(), directoryName), Manager.DefaultOptions
				);
			NUnit.Framework.Assert.IsTrue(migratedOldFile.Exists());
			//cannot rename old.touchdb in old.cblite, old.cblite already exists
			NUnit.Framework.Assert.IsTrue(oldTouchDbFile.Exists());
			NUnit.Framework.Assert.IsTrue(newCbLiteFile.Exists());
			FilePath dir = new FilePath(GetRootDirectory(), directoryName);
			NUnit.Framework.Assert.AreEqual(3, dir.ListFiles().Length);
			base.StopCBLite();
			migratedOldFile.Delete();
			manager = new Manager(new FilePath(GetRootDirectory(), directoryName), Manager.DefaultOptions
				);
			//rename old.touchdb in old.cblite, previous old.cblite already doesn't exist
			NUnit.Framework.Assert.IsTrue(migratedOldFile.Exists());
			NUnit.Framework.Assert.IsTrue(oldTouchDbFile.Exists() == false);
			NUnit.Framework.Assert.IsTrue(newCbLiteFile.Exists());
			dir = new FilePath(GetRootDirectory(), directoryName);
			NUnit.Framework.Assert.AreEqual(2, dir.ListFiles().Length);
		}
Ejemplo n.º 3
0
		public virtual void TestDiff()
		{
			Write(new FilePath(db.Directory.GetParent(), "test.txt"), "test");
			FilePath folder = new FilePath(db.Directory.GetParent(), "folder");
			folder.Mkdir();
			Write(new FilePath(folder, "folder.txt"), "folder");
			Git git = new Git(db);
			git.Add().AddFilepattern(".").Call();
			git.Commit().SetMessage("Initial commit").Call();
			Write(new FilePath(folder, "folder.txt"), "folder change");
			PatchIdDiffFormatter df = new PatchIdDiffFormatter();
			df.SetRepository(db);
			df.SetPathFilter(PathFilter.Create("folder"));
			DirCacheIterator oldTree = new DirCacheIterator(db.ReadDirCache());
			FileTreeIterator newTree = new FileTreeIterator(db);
			df.Format(oldTree, newTree);
			df.Flush();
			NUnit.Framework.Assert.AreEqual("1ff64e0f9333e9b81967c3e8d7a81362b14d5441", df.GetCalulatedPatchId
				().Name);
		}
Ejemplo n.º 4
0
		public virtual void TestDiffModified()
		{
			Write(new FilePath(db.WorkTree, "test.txt"), "test");
			FilePath folder = new FilePath(db.WorkTree, "folder");
			folder.Mkdir();
			Write(new FilePath(folder, "folder.txt"), "folder");
			Git git = new Git(db);
			git.Add().AddFilepattern(".").Call();
			git.Commit().SetMessage("Initial commit").Call();
			Write(new FilePath(folder, "folder.txt"), "folder change");
			OutputStream @out = new ByteArrayOutputStream();
			IList<DiffEntry> entries = git.Diff().SetOutputStream(@out).Call();
			NUnit.Framework.Assert.AreEqual(1, entries.Count);
			NUnit.Framework.Assert.AreEqual(DiffEntry.ChangeType.MODIFY, entries[0].GetChangeType
				());
			NUnit.Framework.Assert.AreEqual("folder/folder.txt", entries[0].GetOldPath());
			NUnit.Framework.Assert.AreEqual("folder/folder.txt", entries[0].GetNewPath());
			string actual = @out.ToString();
			string expected = "diff --git a/folder/folder.txt b/folder/folder.txt\n" + "index 0119635..95c4c65 100644\n"
				 + "--- a/folder/folder.txt\n" + "+++ b/folder/folder.txt\n" + "@@ -1 +1 @@\n" +
				 "-folder\n" + "\\ No newline at end of file\n" + "+folder change\n" + "\\ No newline at end of file\n";
			NUnit.Framework.Assert.AreEqual(expected.ToString(), actual);
		}
Ejemplo n.º 5
0
        /// <summary>
        /// 設定のファイル保存
        /// </summary>
        /// <param name="config">設定</param>
        public void SaveConfig(ConfigEntity config)
        {
            FilePath path = new FilePath(MainWindowModel.ApplicationDataPath);

            if (!path.Exists())
            {
                path.Mkdir();
            }
            string json = JsonConvert.SerializeObject(config, new Newtonsoft.Json.Converters.StringEnumConverter());

            StreamWriter sw = new StreamWriter(MainWindowModel.ConfigFile, false, Encoding.UTF8);

            sw.Write(json);

            sw.Close();
        }
Ejemplo n.º 6
0
		/// <exception cref="System.IO.IOException"></exception>
		public static void CopyFolder(FilePath src, FilePath dest)
		{
			if (src.IsDirectory())
			{
				//if directory not exists, create it
				if (!dest.Exists())
				{
					dest.Mkdir();
				}
				//list all the directory contents
				string[] files = src.List();
				foreach (string file in files)
				{
					//construct the src and dest file structure
					FilePath srcFile = new FilePath(src, file);
					FilePath destFile = new FilePath(dest, file);
					//recursive copy
					CopyFolder(srcFile, destFile);
				}
			}
			else
			{
				CopyFile(src, dest);
			}
		}
Ejemplo n.º 7
0
		public virtual void TestDiff()
		{
			Write(new FilePath(db.Directory.GetParent(), "test.txt"), "test");
			FilePath folder = new FilePath(db.Directory.GetParent(), "folder");
			folder.Mkdir();
			Write(new FilePath(folder, "folder.txt"), "folder");
			Git git = new Git(db);
			git.Add().AddFilepattern(".").Call();
			git.Commit().SetMessage("Initial commit").Call();
			Write(new FilePath(folder, "folder.txt"), "folder change");
			ByteArrayOutputStream os = new ByteArrayOutputStream();
			DiffFormatter df = new DiffFormatter(new BufferedOutputStream(os));
			df.SetRepository(db);
			df.SetPathFilter(PathFilter.Create("folder"));
			DirCacheIterator oldTree = new DirCacheIterator(db.ReadDirCache());
			FileTreeIterator newTree = new FileTreeIterator(db);
			df.Format(oldTree, newTree);
			df.Flush();
			string actual = os.ToString();
			string expected = "diff --git a/folder/folder.txt b/folder/folder.txt\n" + "index 0119635..95c4c65 100644\n"
				 + "--- a/folder/folder.txt\n" + "+++ b/folder/folder.txt\n" + "@@ -1 +1 @@\n" +
				 "-folder\n" + "\\ No newline at end of file\n" + "+folder change\n" + "\\ No newline at end of file\n";
			NUnit.Framework.Assert.AreEqual(expected.ToString(), actual);
		}
Ejemplo n.º 8
0
		public virtual void TestMkdirs()
		{
			FilePath root = new FilePath(trash, "test");
			NUnit.Framework.Assert.IsTrue(root.Mkdir());
			FilePath d = new FilePath(root, "test/test");
			FileUtils.Mkdirs(d);
			NUnit.Framework.Assert.IsTrue(d.Exists() && d.IsDirectory());
			try
			{
				FileUtils.Mkdirs(d);
				NUnit.Framework.Assert.Fail("creation of existing directory hierarchy must fail");
			}
			catch (IOException)
			{
			}
			// expected
			FileUtils.Mkdirs(d, true);
			NUnit.Framework.Assert.IsTrue(d.Exists() && d.IsDirectory());
			FileUtils.Delete(root, FileUtils.RECURSIVE);
			FilePath f = new FilePath(trash, "test");
			FileUtils.CreateNewFile(f);
			try
			{
				FileUtils.Mkdirs(d);
				NUnit.Framework.Assert.Fail("creation of directory having path conflicting with existing"
					 + " file must fail");
			}
			catch (IOException)
			{
			}
			// expected
			NUnit.Framework.Assert.IsTrue(f.Delete());
		}
Ejemplo n.º 9
0
		public virtual void SubmoduleWithNoGitDirectory()
		{
			Git git = new Git(db);
			WriteTrashFile("file.txt", "content");
			git.Add().AddFilepattern("file.txt").Call();
			RevCommit id = git.Commit().SetMessage("create file").Call();
			string path = "sub";
			DirCache cache = db.LockDirCache();
			DirCacheEditor editor = cache.Editor();
			editor.Add(new _PathEdit_311(id, path));
			editor.Commit();
			FilePath submoduleRoot = new FilePath(db.WorkTree, path);
			NUnit.Framework.Assert.IsTrue(submoduleRoot.Mkdir());
			NUnit.Framework.Assert.IsTrue(new FilePath(submoduleRoot, Constants.DOT_GIT).Mkdir
				());
			TreeWalk walk = new TreeWalk(db);
			DirCacheIterator indexIter = new DirCacheIterator(db.ReadDirCache());
			FileTreeIterator workTreeIter = new FileTreeIterator(db);
			walk.AddTree(indexIter);
			walk.AddTree(workTreeIter);
			walk.Filter = PathFilter.Create(path);
			NUnit.Framework.Assert.IsTrue(walk.Next());
			NUnit.Framework.Assert.IsFalse(indexIter.IdEqual(workTreeIter));
			NUnit.Framework.Assert.AreEqual(ObjectId.ZeroId, workTreeIter.EntryObjectId);
		}
Ejemplo n.º 10
0
 /// <summary>Creates the directory named by this abstract pathname.</summary>
 /// <remarks>Creates the directory named by this abstract pathname.</remarks>
 /// <param name="d">directory to be created</param>
 /// <param name="skipExisting">
 /// if
 /// <code>true</code>
 /// skip creation of the given directory if it
 /// already exists in the file system
 /// </param>
 /// <exception cref="System.IO.IOException">
 /// if creation of
 /// <code>d</code>
 /// fails. This may occur if
 /// <code>d</code>
 /// did exist when the method was called. This can therefore
 /// cause IOExceptions during race conditions when multiple
 /// concurrent threads all try to create the same directory.
 /// </exception>
 public static void Mkdir(FilePath d, bool skipExisting)
 {
     if (!d.Mkdir())
     {
         if (skipExisting && d.IsDirectory())
         {
             return;
         }
         throw new IOException(MessageFormat.Format(JGitText.Get().mkDirFailed, d.GetAbsolutePath
             ()));
     }
 }
		/// <exception cref="System.IO.IOException"></exception>
		private PackLock RenameAndOpenPack(string lockMessage)
		{
			if (!keepEmpty && GetObjectCount() == 0)
			{
				CleanupTemporaryFiles();
				return null;
			}
			MessageDigest d = Constants.NewMessageDigest();
			byte[] oeBytes = new byte[Constants.OBJECT_ID_LENGTH];
			for (int i = 0; i < GetObjectCount(); i++)
			{
				PackedObjectInfo oe = GetObject(i);
				oe.CopyRawTo(oeBytes, 0);
				d.Update(oeBytes);
			}
			string name = ObjectId.FromRaw(d.Digest()).Name;
			FilePath packDir = new FilePath(db.GetDirectory(), "pack");
			FilePath finalPack = new FilePath(packDir, "pack-" + name + ".pack");
			FilePath finalIdx = new FilePath(packDir, "pack-" + name + ".idx");
			PackLock keep = new PackLock(finalPack, db.GetFS());
			if (!packDir.Exists() && !packDir.Mkdir() && !packDir.Exists())
			{
				// The objects/pack directory isn't present, and we are unable
				// to create it. There is no way to move this pack in.
				//
				CleanupTemporaryFiles();
				throw new IOException(MessageFormat.Format(JGitText.Get().cannotCreateDirectory, 
					packDir.GetAbsolutePath()));
			}
			if (finalPack.Exists())
			{
				// If the pack is already present we should never replace it.
				//
				CleanupTemporaryFiles();
				return null;
			}
			if (lockMessage != null)
			{
				// If we have a reason to create a keep file for this pack, do
				// so, or fail fast and don't put the pack in place.
				//
				try
				{
					if (!keep.Lock(lockMessage))
					{
						throw new IOException(MessageFormat.Format(JGitText.Get().cannotLockPackIn, finalPack
							));
					}
				}
				catch (IOException e)
				{
					CleanupTemporaryFiles();
					throw;
				}
			}
			if (!tmpPack.RenameTo(finalPack))
			{
				CleanupTemporaryFiles();
				keep.Unlock();
				throw new IOException(MessageFormat.Format(JGitText.Get().cannotMovePackTo, finalPack
					));
			}
			if (!tmpIdx.RenameTo(finalIdx))
			{
				CleanupTemporaryFiles();
				keep.Unlock();
				if (!finalPack.Delete())
				{
					finalPack.DeleteOnExit();
				}
				throw new IOException(MessageFormat.Format(JGitText.Get().cannotMoveIndexTo, finalIdx
					));
			}
			try
			{
				newPack = db.OpenPack(finalPack, finalIdx);
			}
			catch (IOException err)
			{
				keep.Unlock();
				if (finalPack.Exists())
				{
					FileUtils.Delete(finalPack);
				}
				if (finalIdx.Exists())
				{
					FileUtils.Delete(finalIdx);
				}
				throw;
			}
			return lockMessage != null ? keep : null;
		}
Ejemplo n.º 12
0
 public virtual void TestDiffTwoCommits()
 {
     Write(new FilePath(db.WorkTree, "test.txt"), "test");
     FilePath folder = new FilePath(db.WorkTree, "folder");
     folder.Mkdir();
     Write(new FilePath(folder, "folder.txt"), "folder");
     Git git = new Git(db);
     git.Add().AddFilepattern(".").Call();
     git.Commit().SetMessage("Initial commit").Call();
     Write(new FilePath(folder, "folder.txt"), "folder change");
     git.Add().AddFilepattern(".").Call();
     git.Commit().SetMessage("second commit").Call();
     Write(new FilePath(folder, "folder.txt"), "second folder change");
     git.Add().AddFilepattern(".").Call();
     git.Commit().SetMessage("third commit").Call();
     // bad filter
     DiffCommand diff = git.Diff().SetShowNameAndStatusOnly(true).SetPathFilter(PathFilter
         .Create("test.txt")).SetOldTree(GetTreeIterator("HEAD^^")).SetNewTree(GetTreeIterator
         ("HEAD^"));
     IList<DiffEntry> entries = diff.Call();
     NUnit.Framework.Assert.AreEqual(0, entries.Count);
     // no filter, two commits
     OutputStream @out = new ByteArrayOutputStream();
     diff = git.Diff().SetOutputStream(@out).SetOldTree(GetTreeIterator("HEAD^^")).SetNewTree
         (GetTreeIterator("HEAD^"));
     entries = diff.Call();
     NUnit.Framework.Assert.AreEqual(1, entries.Count);
     NUnit.Framework.Assert.AreEqual(DiffEntry.ChangeType.MODIFY, entries[0].GetChangeType
         ());
     NUnit.Framework.Assert.AreEqual("folder/folder.txt", entries[0].GetOldPath());
     NUnit.Framework.Assert.AreEqual("folder/folder.txt", entries[0].GetNewPath());
     string actual = @out.ToString();
     string expected = "diff --git a/folder/folder.txt b/folder/folder.txt\n" + "index 0119635..95c4c65 100644\n"
          + "--- a/folder/folder.txt\n" + "+++ b/folder/folder.txt\n" + "@@ -1 +1 @@\n" +
          "-folder\n" + "\\ No newline at end of file\n" + "+folder change\n" + "\\ No newline at end of file\n";
     NUnit.Framework.Assert.AreEqual(expected.ToString(), actual);
 }
Ejemplo n.º 13
0
		public virtual void RelativeGitDirRef()
		{
			FileRepository repo1 = CreateWorkRepository();
			FilePath dir = new FilePath(repo1.WorkTree, "dir");
			NUnit.Framework.Assert.IsTrue(dir.Mkdir());
			FilePath dotGit = new FilePath(dir, Constants.DOT_GIT);
			new FileWriter(dotGit).Append("gitdir: ../" + Constants.DOT_GIT).Close();
			FileRepositoryBuilder builder = new FileRepositoryBuilder();
			builder.SetWorkTree(dir);
			builder.SetMustExist(true);
			FileRepository repo2 = builder.Build();
			NUnit.Framework.Assert.AreEqual(repo1.Directory, repo2.Directory);
			NUnit.Framework.Assert.AreEqual(dir, repo2.WorkTree);
		}