This repository was archived by the owner on Apr 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 132
Expand file tree
/
Copy pathFileSystem.cs
More file actions
64 lines (54 loc) · 3.62 KB
/
FileSystem.cs
File metadata and controls
64 lines (54 loc) · 3.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using Microsoft.Python.Core.OS;
namespace Microsoft.Python.Core.IO {
public sealed class FileSystem : IFileSystem {
private readonly IOSPlatform _os;
public FileSystem(IOSPlatform os) {
_os = os;
}
public IFileSystemWatcher CreateFileSystemWatcher(string path, string filter) => new FileSystemWatcherProxy(path, filter);
public IDirectoryInfo GetDirectoryInfo(string directoryPath) => new DirectoryInfoProxy(directoryPath);
public bool FileExists(string path) => File.Exists(path);
public long FileSize(string path) {
var fileInfo = new FileInfo(path);
return fileInfo.Length;
}
public string ReadAllText(string filePath) {
if (PathUtils.TryGetZipFilePath(filePath, out var zipPath, out var relativeZipPath)) {
return PathUtils.GetZipContent(zipPath, relativeZipPath);
}
return File.ReadAllText(filePath);
}
public void WriteAllText(string path, string content) => File.WriteAllText(path, content);
public IEnumerable<string> FileReadAllLines(string path) => File.ReadLines(path);
public void FileWriteAllLines(string path, IEnumerable<string> contents) => File.WriteAllLines(path, contents);
public byte[] FileReadAllBytes(string path) => File.ReadAllBytes(path);
public void FileWriteAllBytes(string path, byte[] bytes) => File.WriteAllBytes(path, bytes);
public Stream CreateFile(string path) => File.Create(path);
public Stream FileOpen(string path, FileMode mode) => File.Open(path, mode);
public Stream FileOpen(string path, FileMode mode, FileAccess access, FileShare share) => File.Open(path, mode, access, share);
public bool DirectoryExists(string path) => Directory.Exists(path);
public FileAttributes GetFileAttributes(string path) => File.GetAttributes(path);
public void SetFileAttributes(string fullPath, FileAttributes attributes) => File.SetAttributes(fullPath, attributes);
public DateTime GetLastWriteTimeUtc(string path) => File.GetLastWriteTimeUtc(path);
public Version GetFileVersion(string path) {
var fvi = FileVersionInfo.GetVersionInfo(path);
return new Version(fvi.FileMajorPart, fvi.FileMinorPart, fvi.FileBuildPart, fvi.FilePrivatePart);
}
public void DeleteFile(string path) => File.Delete(path);
public void DeleteDirectory(string path, bool recursive) => Directory.Delete(path, recursive);
public string[] GetFileSystemEntries(string path, string searchPattern, SearchOption options) => Directory.GetFileSystemEntries(path, searchPattern, options);
public void CreateDirectory(string path) => Directory.CreateDirectory(path);
public string[] GetFiles(string path) => Directory.GetFiles(path);
public string[] GetFiles(string path, string pattern) => Directory.GetFiles(path, pattern);
public string[] GetFiles(string path, string pattern, SearchOption option) => Directory.GetFiles(path, pattern, option);
public string[] GetDirectories(string path) => Directory.GetDirectories(path);
public bool IsPathUnderRoot(string root, string path) => Path.GetFullPath(path).StartsWith(root, StringComparison);
public StringComparison StringComparison => _os.IsLinux ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase;
}
}