diff --git a/src/libraries/System.IO.FileSystem.Primitives/src/System/IO/FileAttributes.cs b/src/libraries/System.IO.FileSystem.Primitives/src/System/IO/FileAttributes.cs index 4f078633241..ca4089d5703 100644 --- a/src/libraries/System.IO.FileSystem.Primitives/src/System/IO/FileAttributes.cs +++ b/src/libraries/System.IO.FileSystem.Primitives/src/System/IO/FileAttributes.cs @@ -5,81 +5,25 @@ using System; namespace System.IO { - /// - /// File attribute flags correspondiong to NT's flags. - /// [Flags] [System.Runtime.InteropServices.ComVisible(true)] public enum FileAttributes { - /// - /// [To be supplied.] - /// ReadOnly = 0x0001, - - /// - /// [To be supplied.] - /// Hidden = 0x0002, - - /// - /// [To be supplied.] - /// System = 0x0004, - - /// - /// [To be supplied.] - /// Directory = 0x0010, - - /// - /// [To be supplied.] - /// Archive = 0x0020, - - /// - /// [To be supplied.] - /// Device = 0x0040, - - /// - /// [To be supplied.] - /// Normal = 0x0080, - - /// - /// [To be supplied.] - /// Temporary = 0x0100, - - /// - /// [To be supplied.] - /// SparseFile = 0x0200, - - /// - /// [To be supplied.] - /// ReparsePoint = 0x0400, - - /// - /// [To be supplied.] - /// Compressed = 0x0800, - - /// - /// [To be supplied.] - /// Offline = 0x1000, - - /// - /// [To be supplied.] - /// NotContentIndexed = 0x2000, - - /// - /// [To be supplied.] - /// - Encrypted = 0x4000 + Encrypted = 0x4000, + IntegrityStream = 0x8000, + NoScrubData = 0x20000 } } \ No newline at end of file diff --git a/src/libraries/System.IO.FileSystem/src/System/IO/Directory.cs b/src/libraries/System.IO.FileSystem/src/System/IO/Directory.cs index b36825049fc..e6d691e90b2 100644 --- a/src/libraries/System.IO.FileSystem/src/System/IO/Directory.cs +++ b/src/libraries/System.IO.FileSystem/src/System/IO/Directory.cs @@ -19,6 +19,23 @@ namespace System.IO [ComVisible(true)] public static class Directory { + public static DirectoryInfo GetParent(String path) + { + if (path == null) + throw new ArgumentNullException("path"); + + if (path.Length == 0) + throw new ArgumentException(SR.Argument_PathEmpty, "path"); + Contract.EndContractBlock(); + + String fullPath = PathHelpers.GetFullPathInternal(path); + + String s = Path.GetDirectoryName(fullPath); + if (s == null) + return null; + return new DirectoryInfo(s); + } + [System.Security.SecuritySafeCritical] public static DirectoryInfo CreateDirectory(String path) { @@ -81,7 +98,13 @@ namespace System.IO public static void SetCreationTime(String path, DateTime creationTime) { String fullPath = PathHelpers.GetFullPathInternal(path); - FileSystem.Current.SetCreationTime(fullPath, new DateTimeOffset(creationTime), asDirectory: true); + FileSystem.Current.SetCreationTime(fullPath, creationTime, asDirectory: true); + } + + public static void SetCreationTimeUtc(String path, DateTime creationTime) + { + String fullPath = PathHelpers.GetFullPathInternal(path); + FileSystem.Current.SetCreationTime(fullPath, File.GetUtcDateTimeOffset(creationTime), asDirectory: true); } public static DateTime GetCreationTime(String path) @@ -89,10 +112,21 @@ namespace System.IO return File.GetCreationTime(path); } + public static DateTime GetCreationTimeUtc(String path) + { + return File.GetCreationTimeUtc(path); + } + public static void SetLastWriteTime(String path, DateTime lastWriteTime) { String fullPath = PathHelpers.GetFullPathInternal(path); - FileSystem.Current.SetLastWriteTime(fullPath, new DateTimeOffset(lastWriteTime), asDirectory: true); + FileSystem.Current.SetLastWriteTime(fullPath, lastWriteTime, asDirectory: true); + } + + public static void SetLastWriteTimeUtc(String path, DateTime lastWriteTime) + { + String fullPath = PathHelpers.GetFullPathInternal(path); + FileSystem.Current.SetLastWriteTime(fullPath, File.GetUtcDateTimeOffset(lastWriteTime), asDirectory: true); } public static DateTime GetLastWriteTime(String path) @@ -100,18 +134,33 @@ namespace System.IO return File.GetLastWriteTime(path); } + public static DateTime GetLastWriteTimeUtc(String path) + { + return File.GetLastWriteTimeUtc(path); + } + public static void SetLastAccessTime(String path, DateTime lastAccessTime) { String fullPath = PathHelpers.GetFullPathInternal(path); - FileSystem.Current.SetLastAccessTime(fullPath, new DateTimeOffset(lastAccessTime), asDirectory: true); + FileSystem.Current.SetLastAccessTime(fullPath, lastAccessTime, asDirectory: true); } + public static void SetLastAccessTimeUtc(String path, DateTime lastAccessTime) + { + String fullPath = PathHelpers.GetFullPathInternal(path); + FileSystem.Current.SetLastAccessTime(fullPath, File.GetUtcDateTimeOffset(lastAccessTime), asDirectory: true); + } public static DateTime GetLastAccessTime(String path) { return File.GetLastAccessTime(path); } + public static DateTime GetLastAccessTimeUtc(String path) + { + return File.GetLastAccessTimeUtc(path); + } + // Returns an array of filenames in the DirectoryInfo specified by path public static String[] GetFiles(String path) { diff --git a/src/libraries/System.IO.FileSystem/src/System/IO/File.cs b/src/libraries/System.IO.FileSystem/src/System/IO/File.cs index 0d4fc00eb48..d69cd705622 100644 --- a/src/libraries/System.IO.FileSystem/src/System/IO/File.cs +++ b/src/libraries/System.IO.FileSystem/src/System/IO/File.cs @@ -144,6 +144,12 @@ namespace System.IO return new FileStream(path, FileMode.Create, FileAccess.ReadWrite, FileShare.None, bufferSize); } + public static FileStream Create(String path, int bufferSize, FileOptions options) + { + return new FileStream(path, FileMode.Create, FileAccess.ReadWrite, + FileShare.None, bufferSize, options); + } + // Deletes a file. The file specified by the designated path is deleted. // If the file does not exist, Delete succeeds without throwing // an exception. @@ -225,10 +231,28 @@ namespace System.IO return new FileStream(path, mode, access, share); } + internal static DateTimeOffset GetUtcDateTimeOffset(DateTime dateTime) + { + // File and Directory UTC APIs treat a DateTimeKind.Unspecified as UTC whereas + // ToUniversalTime treats this as local. + if (dateTime.Kind == DateTimeKind.Unspecified) + { + return DateTime.SpecifyKind(dateTime, DateTimeKind.Utc); + } + + return dateTime.ToUniversalTime(); + } + public static void SetCreationTime(String path, DateTime creationTime) { String fullPath = PathHelpers.GetFullPathInternal(path); - FileSystem.Current.SetCreationTime(fullPath, new DateTimeOffset(creationTime), asDirectory: false); + FileSystem.Current.SetCreationTime(fullPath, creationTime, asDirectory: false); + } + + public static void SetCreationTimeUtc(String path, DateTime creationTime) + { + String fullPath = PathHelpers.GetFullPathInternal(path); + FileSystem.Current.SetCreationTime(fullPath, GetUtcDateTimeOffset(creationTime), asDirectory: false); } [System.Security.SecuritySafeCritical] @@ -239,7 +263,7 @@ namespace System.IO } [System.Security.SecuritySafeCritical] // auto-generated - private static DateTime GetCreationTimeUtc(String path) + public static DateTime GetCreationTimeUtc(String path) { String fullPath = PathHelpers.GetFullPathInternal(path); return FileSystem.Current.GetCreationTime(fullPath).UtcDateTime; @@ -248,7 +272,13 @@ namespace System.IO public static void SetLastAccessTime(String path, DateTime lastAccessTime) { String fullPath = PathHelpers.GetFullPathInternal(path); - FileSystem.Current.SetLastAccessTime(fullPath, new DateTimeOffset(lastAccessTime), asDirectory: false); + FileSystem.Current.SetLastAccessTime(fullPath, lastAccessTime, asDirectory: false); + } + + public static void SetLastAccessTimeUtc(String path, DateTime lastAccessTime) + { + String fullPath = PathHelpers.GetFullPathInternal(path); + FileSystem.Current.SetLastAccessTime(fullPath, GetUtcDateTimeOffset(lastAccessTime), asDirectory: false); } [System.Security.SecuritySafeCritical] @@ -259,7 +289,7 @@ namespace System.IO } [System.Security.SecuritySafeCritical] // auto-generated - private static DateTime GetLastAccessTimeUtc(String path) + public static DateTime GetLastAccessTimeUtc(String path) { String fullPath = PathHelpers.GetFullPathInternal(path); return FileSystem.Current.GetLastAccessTime(fullPath).UtcDateTime; @@ -268,7 +298,13 @@ namespace System.IO public static void SetLastWriteTime(String path, DateTime lastWriteTime) { String fullPath = PathHelpers.GetFullPathInternal(path); - FileSystem.Current.SetLastWriteTime(fullPath, new DateTimeOffset(lastWriteTime), asDirectory: false); + FileSystem.Current.SetLastWriteTime(fullPath, lastWriteTime, asDirectory: false); + } + + public static void SetLastWriteTimeUtc(String path, DateTime lastWriteTime) + { + String fullPath = PathHelpers.GetFullPathInternal(path); + FileSystem.Current.SetLastWriteTime(fullPath, GetUtcDateTimeOffset(lastWriteTime), asDirectory: false); } [System.Security.SecuritySafeCritical] @@ -279,7 +315,7 @@ namespace System.IO } [System.Security.SecuritySafeCritical] // auto-generated - private static DateTime GetLastWriteTimeUtc(String path) + public static DateTime GetLastWriteTimeUtc(String path) { String fullPath = PathHelpers.GetFullPathInternal(path); return FileSystem.Current.GetLastWriteTime(fullPath).UtcDateTime; @@ -447,6 +483,29 @@ namespace System.IO fs.Write(bytes, 0, bytes.Length); } } + public static String[] ReadAllLines(String path) + { + if (path == null) + throw new ArgumentNullException("path"); + if (path.Length == 0) + throw new ArgumentException(SR.Argument_EmptyPath); + Contract.EndContractBlock(); + + return InternalReadAllLines(path, Encoding.UTF8); + } + + public static String[] ReadAllLines(String path, Encoding encoding) + { + if (path == null) + throw new ArgumentNullException("path"); + if (encoding == null) + throw new ArgumentNullException("encoding"); + if (path.Length == 0) + throw new ArgumentException(SR.Argument_EmptyPath); + Contract.EndContractBlock(); + + return InternalReadAllLines(path, encoding); + } private static String[] InternalReadAllLines(String path, Encoding encoding) { diff --git a/src/libraries/System.IO.FileSystem/src/System/IO/FileInfo.cs b/src/libraries/System.IO.FileSystem/src/System/IO/FileInfo.cs index a72adeb9da6..4eaa556f6e3 100644 --- a/src/libraries/System.IO.FileSystem/src/System/IO/FileInfo.cs +++ b/src/libraries/System.IO.FileSystem/src/System/IO/FileInfo.cs @@ -98,6 +98,21 @@ namespace System.IO } } + public bool IsReadOnly + { + get + { + return (Attributes & FileAttributes.ReadOnly) != 0; + } + set + { + if (value) + Attributes |= FileAttributes.ReadOnly; + else + Attributes &= ~FileAttributes.ReadOnly; + } + } + [System.Security.SecuritySafeCritical] // auto-generated public StreamReader OpenText() { diff --git a/src/libraries/System.IO.FileSystem/src/System/IO/FileStream.cs b/src/libraries/System.IO.FileSystem/src/System/IO/FileStream.cs index 016b68cf093..13676cbfc30 100644 --- a/src/libraries/System.IO.FileSystem/src/System/IO/FileStream.cs +++ b/src/libraries/System.IO.FileSystem/src/System/IO/FileStream.cs @@ -105,8 +105,10 @@ namespace System.IO if (HasAdditionalInvalidCharacters(fullPath)) throw new ArgumentException(SR.Argument_InvalidPathChars); +#if !PLATFORM_UNIX if (fullPath.IndexOf(':', 2) != -1) throw new NotSupportedException(SR.Argument_PathFormatNotSupported); +#endif if ((access & FileAccess.Read) != 0 && mode == FileMode.Append) throw new ArgumentException(SR.Argument_InvalidAppendMode); diff --git a/src/libraries/System.IO.FileSystem/src/System/IO/FileSystemInfo.cs b/src/libraries/System.IO.FileSystem/src/System/IO/FileSystemInfo.cs index 858ff8c8ff5..68d56c1b2c0 100644 --- a/src/libraries/System.IO.FileSystem/src/System/IO/FileSystemInfo.cs +++ b/src/libraries/System.IO.FileSystem/src/System/IO/FileSystemInfo.cs @@ -102,7 +102,7 @@ namespace System.IO } [ComVisible(false)] - private DateTime CreationTimeUtc + public DateTime CreationTimeUtc { [System.Security.SecuritySafeCritical] get @@ -112,7 +112,7 @@ namespace System.IO set { - FileSystemObject.CreationTime = value; + FileSystemObject.CreationTime = File.GetUtcDateTimeOffset(value); } } @@ -131,7 +131,7 @@ namespace System.IO } [ComVisible(false)] - private DateTime LastAccessTimeUtc + public DateTime LastAccessTimeUtc { [System.Security.SecuritySafeCritical] get @@ -141,7 +141,7 @@ namespace System.IO set { - FileSystemObject.LastAccessTime = value; + FileSystemObject.LastAccessTime = File.GetUtcDateTimeOffset(value); } } @@ -160,7 +160,7 @@ namespace System.IO } [ComVisible(false)] - private DateTime LastWriteTimeUtc + public DateTime LastWriteTimeUtc { [System.Security.SecuritySafeCritical] get @@ -170,7 +170,7 @@ namespace System.IO set { - FileSystemObject.LastWriteTime = value; + FileSystemObject.LastWriteTime = File.GetUtcDateTimeOffset(value); } }