Exemple #1
0
        public Result OpenDirectory(out DirectoryHandle handle, U8Span path, OpenDirectoryMode mode)
        {
            handle = default;

            Result rc = FindFileSystem(out FileSystemAccessor fileSystem, out U8Span subPath, path);

            if (rc.IsFailure())
            {
                return(rc);
            }

            if (IsEnabledAccessLog() && fileSystem.IsAccessLogEnabled)
            {
                TimeSpan startTime = Time.GetCurrent();
                rc     = fileSystem.OpenDirectory(out DirectoryAccessor dir, subPath, mode);
                handle = new DirectoryHandle(dir);
                TimeSpan endTime = Time.GetCurrent();

                OutputAccessLog(rc, startTime, endTime, handle, $", path: \"{path.ToString()}\", open_mode: {mode}");
            }
            else
            {
                rc     = fileSystem.OpenDirectory(out DirectoryAccessor dir, subPath, mode);
                handle = new DirectoryHandle(dir);
            }

            return(rc);
        }
        public static void CopyDirectory(this FileSystemManager fs, string sourcePath, string destPath,
                                         CreateFileOptions options = CreateFileOptions.None, IProgressReport logger = null)
        {
            using (DirectoryHandle sourceHandle = fs.OpenDirectory(sourcePath, OpenDirectoryMode.All))
            {
                foreach (DirectoryEntry entry in fs.ReadDirectory(sourceHandle))
                {
                    string subSrcPath = PathTools.Normalize(PathTools.Combine(sourcePath, entry.Name));
                    string subDstPath = PathTools.Normalize(PathTools.Combine(destPath, entry.Name));

                    if (entry.Type == DirectoryEntryType.Directory)
                    {
                        fs.EnsureDirectoryExists(subDstPath);

                        fs.CopyDirectory(subSrcPath, subDstPath, options, logger);
                    }

                    if (entry.Type == DirectoryEntryType.File)
                    {
                        logger?.LogMessage(subSrcPath);
                        fs.CreateOrOverwriteFile(subDstPath, entry.Size, options);

                        fs.CopyFile(subSrcPath, subDstPath, logger);
                    }
                }
            }
        }
        public static IEnumerable <DirectoryEntry> EnumerateEntries(this FileSystemManager fs, string path, string searchPattern, SearchOptions searchOptions)
        {
            bool ignoreCase = searchOptions.HasFlag(SearchOptions.CaseInsensitive);
            bool recurse    = searchOptions.HasFlag(SearchOptions.RecurseSubdirectories);

            using (DirectoryHandle sourceHandle = fs.OpenDirectory(path, OpenDirectoryMode.All))
            {
                foreach (DirectoryEntry entry in fs.ReadDirectory(sourceHandle))
                {
                    if (PathTools.MatchesPattern(searchPattern, entry.Name, ignoreCase))
                    {
                        yield return(entry);
                    }

                    if (entry.Type != DirectoryEntryType.Directory || !recurse)
                    {
                        continue;
                    }

                    string subPath = PathTools.Normalize(PathTools.Combine(path, entry.Name));

                    IEnumerable <DirectoryEntry> subEntries = fs.EnumerateEntries(subPath, searchPattern, searchOptions);

                    foreach (DirectoryEntry subEntry in subEntries)
                    {
                        subEntry.FullPath = PathTools.Combine(path, subEntry.Name);
                        yield return(subEntry);
                    }
                }
            }
        }
Exemple #4
0
        public IEnumerable <DirectoryEntry> ReadDirectory(DirectoryHandle handle)
        {
            if (IsEnabledAccessLog() && IsEnabledHandleAccessLog(handle))
            {
                TimeSpan startTime = Time.GetCurrent();
                IEnumerable <DirectoryEntry> entries = handle.Directory.Read();
                TimeSpan endTime = Time.GetCurrent();

                OutputAccessLog(startTime, endTime, handle, string.Empty);
                return(entries);
            }

            return(handle.Directory.Read());
        }
Exemple #5
0
        public void CloseDirectory(DirectoryHandle handle)
        {
            if (IsEnabledAccessLog() && IsEnabledHandleAccessLog(handle))
            {
                TimeSpan startTime = Time.GetCurrent();
                handle.Directory.Dispose();
                TimeSpan endTime = Time.GetCurrent();

                OutputAccessLog(startTime, endTime, handle, string.Empty);
            }
            else
            {
                handle.Directory.Dispose();
            }
        }
Exemple #6
0
        public DirectoryHandle OpenDirectory(string path, OpenDirectoryMode mode)
        {
            FindFileSystem(path.AsSpan(), out FileSystemAccessor fileSystem, out ReadOnlySpan <char> subPath)
            .ThrowIfFailure();

            DirectoryHandle handle;

            if (IsEnabledAccessLog() && fileSystem.IsAccessLogEnabled)
            {
                TimeSpan          startTime = Time.GetCurrent();
                DirectoryAccessor dir       = fileSystem.OpenDirectory(subPath.ToString(), mode);
                handle = new DirectoryHandle(dir);
                TimeSpan endTime = Time.GetCurrent();

                OutputAccessLog(startTime, endTime, handle, $", path: \"{path}\", open_mode: {mode}");
            }
            else
            {
                DirectoryAccessor dir = fileSystem.OpenDirectory(subPath.ToString(), mode);
                handle = new DirectoryHandle(dir);
            }

            return(handle);
        }
Exemple #7
0
 internal void OutputAccessLog(Result result, TimeSpan startTime, TimeSpan endTime, DirectoryHandle handle, string message, [CallerMemberName] string caller = "")
 {
     OutputAccessLogImpl(result, startTime, endTime, handle.GetId(), message, caller);
 }
Exemple #8
0
 internal bool IsEnabledHandleAccessLog(DirectoryHandle handle)
 {
     return(handle.Directory.Parent.IsAccessLogEnabled);
 }
Exemple #9
0
 // ==========================
 // Operations on directory handles
 // ==========================
 public int GetDirectoryEntryCount(DirectoryHandle handle)
 {
     return(handle.Directory.GetEntryCount());
 }
 public Result GetDirectoryEntryCount(out long count, DirectoryHandle handle)
 {
     return(handle.Directory.GetEntryCount(out count));
 }
        public Result ReadDirectory(out long entriesRead, Span <DirectoryEntry> entryBuffer, DirectoryHandle handle)
        {
            Result rc;

            if (IsEnabledAccessLog() && IsEnabledHandleAccessLog(handle))
            {
                TimeSpan startTime = Time.GetCurrent();
                rc = handle.Directory.Read(out entriesRead, entryBuffer);
                TimeSpan endTime = Time.GetCurrent();

                OutputAccessLog(rc, startTime, endTime, handle, string.Empty);
            }
            else
            {
                rc = handle.Directory.Read(out entriesRead, entryBuffer);
            }

            return(rc);
        }