CreateNewFile() public method

public CreateNewFile ( ) : bool
return bool
コード例 #1
0
		/// <exception cref="System.IO.IOException"></exception>
		public static void CopyFile(FilePath sourceFile, FilePath destFile)
		{
			if (!destFile.Exists())
			{
				destFile.CreateNewFile();
			}
			FileChannel source = null;
			FileChannel destination = null;
			try
			{
				source = new FileInputStream(sourceFile).GetChannel();
				destination = new FileOutputStream(destFile).GetChannel();
				destination.TransferFrom(source, 0, source.Size());
			}
			finally
			{
				if (source != null)
				{
					source.Close();
				}
				if (destination != null)
				{
					destination.Close();
				}
			}
		}
コード例 #2
0
ファイル: InitCommandTest.cs プロジェクト: LunarLanding/ngit
		public virtual void TestInitNonEmptyRepository()
		{
			FilePath directory = CreateTempDirectory("testInitRepository2");
			FilePath someFile = new FilePath(directory, "someFile");
			someFile.CreateNewFile();
			NUnit.Framework.Assert.IsTrue(someFile.Exists());
			NUnit.Framework.Assert.IsTrue(directory.ListFiles().Length > 0);
			InitCommand command = new InitCommand();
			command.SetDirectory(directory);
			Repository repository = command.Call().GetRepository();
			AddRepoToClose(repository);
			NUnit.Framework.Assert.IsNotNull(repository);
		}
コード例 #3
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);
		}
コード例 #4
0
ファイル: RefDirectoryTest.cs プロジェクト: LunarLanding/ngit
		public virtual void TestRefsChangedStackOverflow()
		{
			FileRepository newRepo = CreateBareRepository();
			RefDatabase refDb = newRepo.RefDatabase;
			FilePath packedRefs = new FilePath(newRepo.Directory, "packed-refs");
			NUnit.Framework.Assert.IsTrue(packedRefs.CreateNewFile());
			AtomicReference<StackOverflowError> error = new AtomicReference<StackOverflowError
				>();
			AtomicReference<IOException> exception = new AtomicReference<IOException>();
			AtomicInteger changeCount = new AtomicInteger();
			newRepo.Listeners.AddRefsChangedListener(new _RefsChangedListener_1156(refDb, changeCount
				, error, exception));
			refDb.GetRefs("ref");
			refDb.GetRefs("ref");
			NUnit.Framework.Assert.IsNull(error.Get());
			NUnit.Framework.Assert.IsNull(exception.Get());
			NUnit.Framework.Assert.AreEqual(1, changeCount.Get());
		}
コード例 #5
0
		/// <summary>Execute this checkout</summary>
		/// <returns>
		/// <code>false</code> if this method could not delete all the files
		/// which should be deleted (e.g. because of of the files was
		/// locked). In this case
		/// <see cref="GetToBeDeleted()">GetToBeDeleted()</see>
		/// lists the files
		/// which should be tried to be deleted outside of this method.
		/// Although <code>false</code> is returned the checkout was
		/// successful and the working tree was updated for all other files.
		/// <code>true</code> is returned when no such problem occurred
		/// </returns>
		/// <exception cref="System.IO.IOException">System.IO.IOException</exception>
		public virtual bool Checkout()
		{
			toBeDeleted.Clear();
			if (headCommitTree != null)
			{
				PreScanTwoTrees();
			}
			else
			{
				PrescanOneTree();
			}
			if (!conflicts.IsEmpty())
			{
				if (failOnConflict)
				{
					dc.Unlock();
					throw new CheckoutConflictException(Sharpen.Collections.ToArray(conflicts, new string
						[conflicts.Count]));
				}
				else
				{
					CleanUpConflicts();
				}
			}
			// update our index
			builder.Finish();
			FilePath file = null;
			string last = string.Empty;
			// when deleting files process them in the opposite order as they have
			// been reported. This ensures the files are deleted before we delete
			// their parent folders
			for (int i = removed.Count - 1; i >= 0; i--)
			{
				string r = removed[i];
				file = new FilePath(repo.WorkTree, r);
				if (!file.Delete() && file.Exists())
				{
					toBeDeleted.AddItem(r);
				}
				else
				{
					if (!IsSamePrefix(r, last))
					{
						RemoveEmptyParents(file);
					}
					last = r;
				}
			}
			if (file != null)
			{
				RemoveEmptyParents(file);
			}
			foreach (string path in updated.Keys)
			{
				// ... create/overwrite this file ...
				file = new FilePath(repo.WorkTree, path);
				file.GetParentFile().Mkdirs();
				file.CreateNewFile();
				DirCacheEntry entry = dc.GetEntry(path);
				CheckoutEntry(repo, file, entry);
			}
			// commit the index builder - a new index is persisted
			if (!builder.Commit())
			{
				dc.Unlock();
				throw new IndexWriteException();
			}
			return toBeDeleted.Count == 0;
		}
コード例 #6
0
ファイル: FileUtils.cs プロジェクト: kenji-tan/ngit
 /// <summary>
 /// Atomically creates a new, empty file named by this abstract pathname if
 /// and only if a file with this name does not yet exist.
 /// </summary>
 /// <remarks>
 /// Atomically creates a new, empty file named by this abstract pathname if
 /// and only if a file with this name does not yet exist. The check for the
 /// existence of the file and the creation of the file if it does not exist
 /// are a single operation that is atomic with respect to all other
 /// filesystem activities that might affect the file.
 /// <p>
 /// Note: this method should not be used for file-locking, as the resulting
 /// protocol cannot be made to work reliably. The
 /// <see cref="Sharpen.FileLock">Sharpen.FileLock</see>
 /// facility
 /// should be used instead.
 /// </remarks>
 /// <param name="f">the file to be created</param>
 /// <exception cref="System.IO.IOException">if the named file already exists or if an I/O error occurred
 /// 	</exception>
 public static void CreateNewFile(FilePath f)
 {
     if (!f.CreateNewFile())
     {
         throw new IOException(MessageFormat.Format(JGitText.Get().createNewFileFailed, f)
             );
     }
 }