//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private int scrambleIndexFiles(org.neo4j.io.fs.FileSystemAbstraction fs, java.io.File fileOrDir) throws java.io.IOException private int ScrambleIndexFiles(FileSystemAbstraction fs, File fileOrDir) { if (fs.IsDirectory(fileOrDir)) { int count = 0; File[] children = fs.ListFiles(fileOrDir); if (children != null) { foreach (File child in children) { count += ScrambleIndexFiles(fs, child); } } return(count); } else { // Completely scramble file, assuming small files using (StoreChannel channel = fs.Open(fileOrDir, OpenMode.READ_WRITE)) { if (channel.size() > mebiBytes(10)) { throw new System.ArgumentException("Was expecting small files here"); } sbyte[] bytes = new sbyte[( int )channel.size()]; _random.NextBytes(bytes); channel.WriteAll(ByteBuffer.wrap(bytes)); } return(1); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldWorkCorrectlyOnReasonableDirectoryContents() public virtual void ShouldWorkCorrectlyOnReasonableDirectoryContents() { // Given // a raft log directory with just the expected files, without gaps File @base = new File("base"); FileNames fileNames = new FileNames(@base); FileSystemAbstraction fsa = mock(typeof(FileSystemAbstraction)); Log log = mock(typeof(Log)); IList <File> filesPresent = new LinkedList <File>(); int lower = 0; int upper = 24; // the files are added in reverse order, so we can verify that FileNames orders based on version for (int i = upper; i >= lower; i--) { filesPresent.Add(fileNames.GetForVersion(i)); } when(fsa.ListFiles(@base)).thenReturn(filesPresent.ToArray()); // When // asked for the contents of the directory SortedDictionary <long, File> allFiles = fileNames.GetAllFiles(fsa, log); // Then // all the things we added above should be returned assertEquals(upper - lower + 1, allFiles.Count); long currentVersion = lower; foreach (KeyValuePair <long, File> longFileEntry in allFiles.SetOfKeyValuePairs()) { assertEquals(currentVersion, longFileEntry.Key.longValue()); assertEquals(fileNames.GetForVersion(currentVersion), longFileEntry.Value); currentVersion++; } }
private static bool IsEmptyDirectory(FileSystemAbstraction fileSystem, File sourceToCompress) { if (fileSystem.IsDirectory(sourceToCompress)) { File[] files = fileSystem.ListFiles(sourceToCompress); return(files == null || Files.Length == 0); } return(false); }
internal static Stream <Profile> FindProfilesInDirectory(FileSystemAbstraction fs, File dir) { File[] files = fs.ListFiles(new File(dir, PROFILE_DIR)); if (files == null) { return(Stream.empty()); } return(Stream.of(files).flatMap(Profile.parseProfileName)); }
private static void ListFiles(FileSystemAbstraction fileSystem, DatabaseLayout databaseLayout) { File databaseDirectory = databaseLayout.DatabaseDirectory(); File[] listing = fileSystem.ListFiles(databaseDirectory); foreach (File file in listing) { _console.printf("%s%n", file.Name); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public static void dump(org.neo4j.io.fs.FileSystemAbstraction fs, org.neo4j.io.layout.DatabaseLayout databaseLayout, Dumper dumper, TxFilter txFilter) throws java.io.IOException public static void Dump(FileSystemAbstraction fs, DatabaseLayout databaseLayout, Dumper dumper, TxFilter txFilter) { File writeLogFile = WriteLogBaseFile(databaseLayout); string writeLogFileBaseName = writeLogFile.Name; File[] files = fs.ListFiles(databaseLayout.DatabaseDirectory(), (dir, name) => name.StartsWith(writeLogFileBaseName)); Arrays.sort(files, comparing(_file => _file.Name.Equals(writeLogFileBaseName) ? 0 : MillisOf(_file))); long session = 0; foreach (File file in files) { dumper.File(file); session = DumpFile(fs, file, dumper, txFilter, session); } }
private static Stream <File> StreamFilesRecursiveInner(File directory, FileSystemAbstraction fs) { File[] files = fs.ListFiles(directory); if (files == null) { if (!fs.FileExists(directory)) { return(Stream.empty()); } return(Stream.of(directory)); } else { return(Stream.of(files).flatMap(f => fs.IsDirectory(f) ? StreamFilesRecursiveInner(f, fs) : Stream.of(f))); } }
/// <summary> /// Looks in the base directory for all suitable RAFT log files and returns a sorted map /// with the version as key and File as value. /// </summary> /// <param name="fileSystem"> The filesystem. </param> /// <param name="log"> The message log. /// </param> /// <returns> The sorted version to file map. </returns> public virtual SortedDictionary <long, File> GetAllFiles(FileSystemAbstraction fileSystem, Log log) { SortedDictionary <long, File> versionFileMap = new SortedDictionary <long, File>(); foreach (File file in fileSystem.ListFiles(_baseDirectory)) { Matcher matcher = _logFilePattern.matcher(file.Name); if (!matcher.matches()) { log.Warn("Found out of place file: " + file.Name); continue; } versionFileMap[Convert.ToInt64(matcher.group(1))] = file; } return(versionFileMap); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void overrideDestination() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: internal virtual void OverrideDestination() { // because of https://bugs.openjdk.java.net/browse/JDK-8202127 and current surefire behaviour we need to have custom value for JRE >= 11 string toArgument = JRE.JAVA_11.CurrentVersion ? "--to=" + System.getProperty("user.dir") + "/other/" : "--to=other/"; string[] args = new string[] { toArgument, "all" }; using (RealOutsideWorld outsideWorld = new RealOutsideWorld()) { DiagnosticsReportCommand diagnosticsReportCommand = new DiagnosticsReportCommand(_homeDir, _configDir, outsideWorld); diagnosticsReportCommand.Execute(args); File other = _testDirectory.directory("other"); FileSystemAbstraction fs = outsideWorld.FileSystem(); assertThat(fs.FileExists(other), @is(true)); assertThat(fs.ListFiles(other).Length, @is(1)); // Default should be empty File reports = new File(_testDirectory.directory(), "reports"); assertThat(fs.FileExists(reports), @is(false)); } }
/// <summary> /// Calculates the size of a given directory or file given the provided abstract filesystem. /// </summary> /// <param name="fs"> the filesystem abstraction to use </param> /// <param name="file"> to the file or directory. </param> /// <returns> the size, in bytes, of the file or the total size of the content in the directory, including /// subdirectories. </returns> public static long Size(FileSystemAbstraction fs, File file) { if (fs.IsDirectory(file)) { long size = 0L; File[] files = fs.ListFiles(file); if (files == null) { return(0L); } foreach (File child in files) { size += size(fs, child); } return(size); } else { return(fs.GetFileSize(file)); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldIgnoreUnexpectedLogDirectoryContents() public virtual void ShouldIgnoreUnexpectedLogDirectoryContents() { // Given // a raft log directory with just the expected files, without gaps File @base = new File("base"); FileNames fileNames = new FileNames(@base); FileSystemAbstraction fsa = mock(typeof(FileSystemAbstraction)); Log log = mock(typeof(Log)); IList <File> filesPresent = new LinkedList <File>(); filesPresent.Add(fileNames.GetForVersion(0)); // should be included filesPresent.Add(fileNames.GetForVersion(1)); // should be included filesPresent.Add(fileNames.GetForVersion(10)); // should be included filesPresent.Add(fileNames.GetForVersion(11)); // should be included filesPresent.Add(new File(@base, FileNames.BASE_FILE_NAME + "01")); // should be ignored filesPresent.Add(new File(@base, FileNames.BASE_FILE_NAME + "001")); // should be ignored filesPresent.Add(new File(@base, FileNames.BASE_FILE_NAME)); // should be ignored filesPresent.Add(new File(@base, FileNames.BASE_FILE_NAME + "-1")); // should be ignored filesPresent.Add(new File(@base, FileNames.BASE_FILE_NAME + "1a")); // should be ignored filesPresent.Add(new File(@base, FileNames.BASE_FILE_NAME + "a1")); // should be ignored filesPresent.Add(new File(@base, FileNames.BASE_FILE_NAME + "ab")); // should be ignored when(fsa.ListFiles(@base)).thenReturn(filesPresent.ToArray()); // When // asked for the contents of the directory SortedDictionary <long, File> allFiles = fileNames.GetAllFiles(fsa, log); // Then // only valid things should be returned assertEquals(4, allFiles.Count); assertEquals(allFiles[0L], fileNames.GetForVersion(0)); assertEquals(allFiles[1L], fileNames.GetForVersion(1)); assertEquals(allFiles[10L], fileNames.GetForVersion(10)); assertEquals(allFiles[11L], fileNames.GetForVersion(11)); // and the invalid ones should be logged verify(log, times(7)).warn(anyString()); }
/// <summary> /// Deletes index folder with the specific indexId, but has the option to first archive the index if it exists. /// The zip archive will be placed next to the root directory for that index with a timestamp included in its name. /// </summary> /// <param name="fs"> <seealso cref="FileSystemAbstraction"/> this index lives in. </param> /// <param name="directoryStructure"> <seealso cref="IndexDirectoryStructure"/> knowing the directory structure for the provider owning the index. </param> /// <param name="indexId"> id of the index. </param> /// <param name="archiveIfExists"> whether or not to archive the index before deleting it, if it exists. </param> /// <returns> whether or not an archive was created. </returns> /// <exception cref="IOException"> on I/O error. </exception> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public static boolean deleteIndex(org.neo4j.io.fs.FileSystemAbstraction fs, org.neo4j.kernel.api.index.IndexDirectoryStructure directoryStructure, long indexId, boolean archiveIfExists) throws java.io.IOException public static bool DeleteIndex(FileSystemAbstraction fs, IndexDirectoryStructure directoryStructure, long indexId, bool archiveIfExists) { File rootIndexDirectory = directoryStructure.DirectoryForIndex(indexId); if (archiveIfExists && fs.IsDirectory(rootIndexDirectory) && fs.FileExists(rootIndexDirectory) && fs.ListFiles(rootIndexDirectory).Length > 0) { ZipUtils.zip(fs, rootIndexDirectory, new File(rootIndexDirectory.Parent, "archive-" + rootIndexDirectory.Name + "-" + DateTimeHelper.CurrentUnixTimeMillis() + ".zip")); return(true); } int attempt = 0; while (attempt < 5) { attempt++; try { fs.DeleteRecursively(rootIndexDirectory); break; } catch (Exception concurrentModificationException) when(concurrentModificationException is DirectoryNotEmptyException || concurrentModificationException is NoSuchFileException) { // Looks like someone was poking around in our directory while we where deleting. // Let's sleep for a bit and try again. try { Thread.Sleep(100); } catch (InterruptedException) { // Let's abandon this attempt to clean up. Thread.CurrentThread.Interrupt(); break; } } } return(false); }