ListFiles() public method

public ListFiles ( ) : Sharpen.FilePath[]
return Sharpen.FilePath[]
Example #1
0
		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());
		}
Example #2
0
		public static bool DeleteRecursive(FilePath fileOrDirectory)
		{
			if (fileOrDirectory.IsDirectory())
			{
				foreach (FilePath child in fileOrDirectory.ListFiles())
				{
					DeleteRecursive(child);
				}
			}
			bool result = fileOrDirectory.Delete() || !fileOrDirectory.Exists();
			return result;
		}
Example #3
0
		private static void AddCategories(TestSuite suite, FilePath suiteDir, string prefix, string[] excludes, int optimizationLevel)
		{
			FilePath[] subdirs = suiteDir.ListFiles(ShellTest.DIRECTORY_FILTER);
			Arrays.Sort(subdirs);
			for (int i = 0; i < subdirs.Length; i++)
			{
				FilePath subdir = subdirs[i];
				string name = subdir.GetName();
				TestSuite testCategory = new TestSuite(name);
				AddTests(testCategory, subdir, prefix + name + "/", excludes, optimizationLevel);
				suite.AddTest(testCategory);
			}
		}
Example #4
0
		private static void AddTests(TestSuite suite, FilePath suiteDir, string prefix, string[] excludes, int optimizationLevel)
		{
			FilePath[] jsFiles = suiteDir.ListFiles(ShellTest.TEST_FILTER);
			Arrays.Sort(jsFiles);
			for (int i = 0; i < jsFiles.Length; i++)
			{
				FilePath jsFile = jsFiles[i];
				string name = jsFile.GetName();
				if (!TestUtils.Matches(excludes, prefix + name))
				{
					suite.AddTest(new StandardTests.JsTestCase(jsFile, optimizationLevel));
				}
			}
		}
Example #5
0
		public static void RecursiveListFilesHelper(FilePath dir, FileFilter filter, IList<FilePath> fileList)
		{
			foreach (FilePath f in dir.ListFiles())
			{
				if (f.IsDirectory())
				{
					RecursiveListFilesHelper(f, filter, fileList);
				}
				else
				{
					if (filter.Accept(f))
					{
						fileList.Add(f);
					}
				}
			}
		}
Example #6
0
		private static void AddSuites(TestSuite topLevel, FilePath testDir, string[] excludes, int optimizationLevel)
		{
			FilePath[] subdirs = testDir.ListFiles(ShellTest.DIRECTORY_FILTER);
			Arrays.Sort(subdirs);
			for (int i = 0; i < subdirs.Length; i++)
			{
				FilePath subdir = subdirs[i];
				string name = subdir.GetName();
				if (TestUtils.Matches(excludes, name))
				{
					continue;
				}
				TestSuite testSuite = new TestSuite(name);
				AddCategories(testSuite, subdir, name + "/", excludes, optimizationLevel);
				topLevel.AddTest(testSuite);
			}
		}
Example #7
0
		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());
					}
				}
			}
		}
Example #8
0
 private void UpgradeOldDatabaseFiles(FilePath directory)
 {
     FilePath[] files = directory.ListFiles(new _FilenameFilter_330());
     foreach (FilePath file in files)
     {
         string oldFilename = file.GetName();
         string newFilename = FilenameWithNewExtension(oldFilename, DatabaseSuffixOld, DatabaseSuffix
             );
         FilePath newFile = new FilePath(directory, newFilename);
         if (newFile.Exists())
         {
             Log.W(Database.Tag, "Cannot rename %s to %s, %s already exists", oldFilename, newFilename
                 , newFilename);
             continue;
         }
         bool ok = file.RenameTo(newFile);
         if (!ok)
         {
             string msg = string.Format("Unable to rename %s to %s", oldFilename, newFilename);
             throw new InvalidOperationException(msg);
         }
     }
 }
Example #9
0
		/// <summary>Delete file or folder</summary>
		/// <param name="f">
		/// <code>File</code>
		/// to be deleted
		/// </param>
		/// <param name="options">
		/// deletion options,
		/// <code>RECURSIVE</code>
		/// for recursive deletion of
		/// a subtree,
		/// <code>RETRY</code>
		/// to retry when deletion failed.
		/// Retrying may help if the underlying file system doesn't allow
		/// deletion of files being read by another thread.
		/// </param>
		/// <exception cref="System.IO.IOException">
		/// if deletion of
		/// <code>f</code>
		/// fails. This may occur if
		/// <code>f</code>
		/// didn't exist when the method was called. This can therefore
		/// cause IOExceptions during race conditions when multiple
		/// concurrent threads all try to delete the same file.
		/// </exception>
		public static void Delete(FilePath f, int options)
		{
			if ((options & SKIP_MISSING) != 0 && !f.Exists())
			{
				return;
			}
			if ((options & RECURSIVE) != 0 && f.IsDirectory())
			{
				FilePath[] items = f.ListFiles();
				if (items != null)
				{
					foreach (FilePath c in items)
					{
						Delete(c, options);
					}
				}
			}
			if (!f.Delete())
			{
				if ((options & RETRY) != 0 && f.Exists())
				{
					for (int i = 1; i < 10; i++)
					{
						try
						{
							Sharpen.Thread.Sleep(100);
						}
						catch (Exception)
						{
						}
						// ignore
						if (f.Delete())
						{
							return;
						}
					}
				}
				throw new IOException(MessageFormat.Format(JGitText.Get().deleteFileFailed, f.GetAbsolutePath
					()));
			}
		}
Example #10
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);
		}
		private void ListFiles(FilePath dir, AList<string> list)
		{
			foreach (FilePath f in dir.ListFiles())
			{
				if (f.IsDirectory())
				{
					ListFiles(f, list);
				}
				else
				{
					list.AddItem(Repository.StripWorkDir(root, f));
				}
			}
		}
Example #12
0
			private void AddFiles(IList<JsDriver.Tests.Script> rv, string prefix, FilePath directory)
			{
				FilePath[] files = directory.ListFiles();
				if (files == null)
				{
					throw new Exception("files null for " + directory);
				}
				for (int i = 0; i < files.Length; i++)
				{
					string path = prefix + files[i].GetName();
					if (ShellTest.DIRECTORY_FILTER.Accept(files[i]))
					{
						AddFiles(rv, path + "/", files[i]);
					}
					else
					{
						bool isTopLevel = prefix.Length == 0;
						if (ShellTest.TEST_FILTER.Accept(files[i]) && Matches(path) && !Excluded(path) && !isTopLevel)
						{
							rv.Add(new JsDriver.Tests.Script(path, files[i]));
						}
					}
				}
			}
 public int DeleteBlobsExceptWithKeys(IList<BlobKey> keysToKeep)
 {
     int numDeleted = 0;
     FilePath file = new FilePath(path);
     FilePath[] contents = file.ListFiles();
     foreach (FilePath attachment in contents)
     {
         BlobKey attachmentKey = new BlobKey();
         GetKeyForFilename(attachmentKey, attachment.GetPath());
         if (!keysToKeep.Contains(attachmentKey))
         {
             bool result = attachment.Delete();
             if (result)
             {
                 ++numDeleted;
             }
             else
             {
                 Log.E(Database.Tag, "Error deleting attachmetn");
             }
         }
     }
     return numDeleted;
 }
 public long TotalDataSize()
 {
     long total = 0;
     FilePath file = new FilePath(path);
     FilePath[] contents = file.ListFiles();
     foreach (FilePath attachment in contents)
     {
         total += attachment.Length();
     }
     return total;
 }
 public int Count()
 {
     FilePath file = new FilePath(path);
     FilePath[] contents = file.ListFiles();
     return contents.Length;
 }
 public ICollection<BlobKey> AllKeys()
 {
     ICollection<BlobKey> result = new HashSet<BlobKey>();
     FilePath file = new FilePath(path);
     FilePath[] contents = file.ListFiles();
     foreach (FilePath attachment in contents)
     {
         if (attachment.IsDirectory())
         {
             continue;
         }
         BlobKey attachmentKey = new BlobKey();
         GetKeyForFilename(attachmentKey, attachment.GetPath());
         result.AddItem(attachmentKey);
     }
     return result;
 }