You've already forked linux-packaging-mono
Imported Upstream version 4.6.0.125
Former-commit-id: a2155e9bd80020e49e72e86c44da02a8ac0e57a4
This commit is contained in:
parent
a569aebcfd
commit
e79aa3c0ed
File diff suppressed because it is too large
Load Diff
@@ -96,7 +96,7 @@ namespace System.IO
|
||||
info.Parent.Create ();
|
||||
|
||||
MonoIOError error;
|
||||
if (!MonoIO.CreateDirectory (path, out error)) {
|
||||
if (!MonoIO.CreateDirectory (info.FullName, out error)) {
|
||||
// LAMESPEC: 1.1 and 1.2alpha allow CreateDirectory on a file path.
|
||||
// So CreateDirectory ("/tmp/somefile") will succeed if 'somefile' is
|
||||
// not a directory. However, 1.0 will throw an exception.
|
||||
@@ -645,5 +645,28 @@ namespace System.IO
|
||||
AccessControlSections.Group |
|
||||
AccessControlSections.Access);
|
||||
}
|
||||
|
||||
#region Copied from reference source
|
||||
internal static String GetDemandDir(string fullPath, bool thisDirOnly)
|
||||
{
|
||||
String demandPath;
|
||||
|
||||
if (thisDirOnly) {
|
||||
if (fullPath.EndsWith( Path.DirectorySeparatorChar )
|
||||
|| fullPath.EndsWith( Path.AltDirectorySeparatorChar ) )
|
||||
demandPath = fullPath + ".";
|
||||
else
|
||||
demandPath = fullPath + Path.DirectorySeparatorCharAsString + ".";
|
||||
}
|
||||
else {
|
||||
if (!(fullPath.EndsWith( Path.DirectorySeparatorChar )
|
||||
|| fullPath.EndsWith( Path.AltDirectorySeparatorChar )) )
|
||||
demandPath = fullPath + Path.DirectorySeparatorCharAsString;
|
||||
else
|
||||
demandPath = fullPath;
|
||||
}
|
||||
return demandPath;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ namespace System.IO {
|
||||
|
||||
FullPath = Path.GetFullPath (path);
|
||||
if (simpleOriginalPath)
|
||||
OriginalPath = Path.GetFileName (path);
|
||||
OriginalPath = Path.GetFileName (FullPath);
|
||||
else
|
||||
OriginalPath = path;
|
||||
|
||||
@@ -102,12 +102,13 @@ namespace System.IO {
|
||||
|
||||
public override bool Exists {
|
||||
get {
|
||||
Refresh (false);
|
||||
if (_dataInitialised == -1)
|
||||
Refresh ();
|
||||
|
||||
if (stat.Attributes == MonoIO.InvalidFileAttributes)
|
||||
if (_data.fileAttributes == MonoIO.InvalidFileAttributes)
|
||||
return false;
|
||||
|
||||
if ((stat.Attributes & FileAttributes.Directory) == 0)
|
||||
if ((_data.fileAttributes & FileAttributes.Directory) == 0)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
@@ -458,6 +459,19 @@ namespace System.IO {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
internal void CheckPath (string path)
|
||||
{
|
||||
if (path == null)
|
||||
throw new ArgumentNullException ("path");
|
||||
if (path.Length == 0)
|
||||
throw new ArgumentException ("An empty file name is not valid.");
|
||||
if (path.IndexOfAny (Path.InvalidPathChars) != -1)
|
||||
throw new ArgumentException ("Illegal characters in path.");
|
||||
if (Environment.IsRunningOnWindows) {
|
||||
int idx = path.IndexOf (':');
|
||||
if (idx >= 0 && idx != 1)
|
||||
throw new ArgumentException ("path");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,6 +113,21 @@ namespace System.IO
|
||||
}
|
||||
}
|
||||
|
||||
internal static String InternalCopy (String sourceFileName, String destFileName, bool overwrite, bool checkHost)
|
||||
{
|
||||
String fullSourceFileName = Path.GetFullPathInternal(sourceFileName);
|
||||
String fullDestFileName = Path.GetFullPathInternal(destFileName);
|
||||
|
||||
MonoIOError error;
|
||||
|
||||
if (!MonoIO.CopyFile (fullSourceFileName, fullDestFileName, overwrite, out error)) {
|
||||
string p = Locale.GetText ("{0}\" or \"{1}", sourceFileName, destFileName);
|
||||
throw MonoIO.GetException (p, error);
|
||||
}
|
||||
|
||||
return fullDestFileName;
|
||||
}
|
||||
|
||||
public static FileStream Create (string path)
|
||||
{
|
||||
return Create (path, 8192);
|
||||
@@ -124,14 +139,15 @@ namespace System.IO
|
||||
FileShare.None, bufferSize);
|
||||
}
|
||||
|
||||
#if !NET_2_1
|
||||
[MonoLimitation ("FileOptions are ignored")]
|
||||
public static FileStream Create (string path, int bufferSize,
|
||||
FileOptions options)
|
||||
{
|
||||
return Create (path, bufferSize, options, null);
|
||||
return new FileStream (path, FileMode.Create, FileAccess.ReadWrite,
|
||||
FileShare.None, bufferSize, options);
|
||||
}
|
||||
|
||||
|
||||
#if !NET_2_1
|
||||
[MonoLimitation ("FileOptions and FileSecurity are ignored")]
|
||||
public static FileStream Create (string path, int bufferSize,
|
||||
FileOptions options,
|
||||
@@ -406,6 +422,12 @@ namespace System.IO
|
||||
"Destination and backup arguments are the same file."));
|
||||
}
|
||||
|
||||
var attrs = GetAttributes (fullDest);
|
||||
|
||||
// TODO: Should be done in wapi, win32 api handles this already
|
||||
if ((attrs & FileAttributes.ReadOnly) != 0)
|
||||
throw MonoIO.GetException (MonoIOError.ERROR_ACCESS_DENIED);
|
||||
|
||||
if (!MonoIO.ReplaceFile (fullSource, fullDest, fullBackup,
|
||||
ignoreMetadataErrors, out error)) {
|
||||
throw MonoIO.GetException (error);
|
||||
@@ -688,5 +710,22 @@ namespace System.IO
|
||||
w.WriteLine (line);
|
||||
}
|
||||
}
|
||||
|
||||
internal static int FillAttributeInfo (String path, ref MonoIOStat data, bool tryagain, bool returnErrorOnNotFound)
|
||||
{
|
||||
if (tryagain)
|
||||
throw new NotImplementedException ();
|
||||
|
||||
MonoIOError error;
|
||||
MonoIO.GetFileStat (path, out data, out error);
|
||||
|
||||
if (!returnErrorOnNotFound && (error == MonoIOError.ERROR_FILE_NOT_FOUND || error == MonoIOError.ERROR_PATH_NOT_FOUND || error == MonoIOError.ERROR_NOT_READY)) {
|
||||
data = default (MonoIOStat);
|
||||
data.fileAttributes = (FileAttributes) (-1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (int) error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,327 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
//
|
||||
// System.IO.FileInfo.cs
|
||||
//
|
||||
// Copyright (C) 2001 Moonlight Enterprises, All Rights Reserved
|
||||
//
|
||||
// Author: Jim Richardson, develop@wtfo-guru.com
|
||||
// Dan Lewis (dihlewis@yahoo.co.uk)
|
||||
// Created: Monday, August 13, 2001
|
||||
//
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//
|
||||
// Copyright (C) 2004, 2006 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Security;
|
||||
|
||||
#if !MOBILE
|
||||
using System.Security.AccessControl;
|
||||
#endif
|
||||
|
||||
namespace System.IO {
|
||||
|
||||
[Serializable]
|
||||
[ComVisible (true)]
|
||||
public sealed class FileInfo : FileSystemInfo
|
||||
{
|
||||
private bool exists;
|
||||
|
||||
public FileInfo (string fileName)
|
||||
{
|
||||
if (fileName == null)
|
||||
throw new ArgumentNullException ("fileName");
|
||||
|
||||
CheckPath (fileName);
|
||||
SecurityManager.EnsureElevatedPermissions (); // this is a no-op outside moonlight
|
||||
|
||||
OriginalPath = fileName;
|
||||
FullPath = Path.GetFullPath (fileName);
|
||||
}
|
||||
|
||||
private FileInfo (SerializationInfo info, StreamingContext context)
|
||||
: base (info, context)
|
||||
{
|
||||
}
|
||||
|
||||
internal override void InternalRefresh ()
|
||||
{
|
||||
exists = File.Exists (FullPath);
|
||||
}
|
||||
|
||||
// public properties
|
||||
|
||||
public override bool Exists {
|
||||
get {
|
||||
Refresh (false);
|
||||
|
||||
if (stat.Attributes == MonoIO.InvalidFileAttributes)
|
||||
return false;
|
||||
|
||||
if ((stat.Attributes & FileAttributes.Directory) != 0)
|
||||
return false;
|
||||
|
||||
return exists;
|
||||
}
|
||||
}
|
||||
|
||||
public override string Name {
|
||||
get {
|
||||
return Path.GetFileName (FullPath);
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsReadOnly {
|
||||
get {
|
||||
if (!Exists)
|
||||
throw new FileNotFoundException ("Could not find file \"" + OriginalPath + "\".", OriginalPath);
|
||||
|
||||
return ((stat.Attributes & FileAttributes.ReadOnly) != 0);
|
||||
}
|
||||
|
||||
set {
|
||||
if (!Exists)
|
||||
throw new FileNotFoundException ("Could not find file \"" + OriginalPath + "\".", OriginalPath);
|
||||
|
||||
FileAttributes attrs = File.GetAttributes(FullPath);
|
||||
|
||||
if (value)
|
||||
attrs |= FileAttributes.ReadOnly;
|
||||
else
|
||||
attrs &= ~FileAttributes.ReadOnly;
|
||||
|
||||
File.SetAttributes(FullPath, attrs);
|
||||
}
|
||||
}
|
||||
|
||||
[MonoLimitation ("File encryption isn't supported (even on NTFS).")]
|
||||
[ComVisible (false)]
|
||||
public void Encrypt ()
|
||||
{
|
||||
// MS.NET support this only on NTFS file systems, i.e. it's a file-system (not a framework) feature.
|
||||
// otherwise it throws a NotSupportedException (or a PlatformNotSupportedException on older OS).
|
||||
// we throw the same (instead of a NotImplementedException) because most code should already be
|
||||
// handling this exception to work properly.
|
||||
throw new NotSupportedException (Locale.GetText ("File encryption isn't supported on any file system."));
|
||||
}
|
||||
|
||||
[MonoLimitation ("File encryption isn't supported (even on NTFS).")]
|
||||
[ComVisible (false)]
|
||||
public void Decrypt ()
|
||||
{
|
||||
// MS.NET support this only on NTFS file systems, i.e. it's a file-system (not a framework) feature.
|
||||
// otherwise it throws a NotSupportedException (or a PlatformNotSupportedException on older OS).
|
||||
// we throw the same (instead of a NotImplementedException) because most code should already be
|
||||
// handling this exception to work properly.
|
||||
throw new NotSupportedException (Locale.GetText ("File encryption isn't supported on any file system."));
|
||||
}
|
||||
|
||||
public long Length {
|
||||
get {
|
||||
if (!Exists)
|
||||
throw new FileNotFoundException ("Could not find file \"" + OriginalPath + "\".", OriginalPath);
|
||||
|
||||
return stat.Length;
|
||||
}
|
||||
}
|
||||
|
||||
public string DirectoryName {
|
||||
get {
|
||||
return Path.GetDirectoryName (FullPath);
|
||||
}
|
||||
}
|
||||
|
||||
public DirectoryInfo Directory {
|
||||
get {
|
||||
return new DirectoryInfo (DirectoryName);
|
||||
}
|
||||
}
|
||||
|
||||
// streamreader methods
|
||||
|
||||
public StreamReader OpenText ()
|
||||
{
|
||||
return new StreamReader (Open (FileMode.Open, FileAccess.Read));
|
||||
}
|
||||
|
||||
public StreamWriter CreateText ()
|
||||
{
|
||||
return new StreamWriter (Open (FileMode.Create, FileAccess.Write));
|
||||
}
|
||||
|
||||
public StreamWriter AppendText ()
|
||||
{
|
||||
return new StreamWriter (Open (FileMode.Append, FileAccess.Write));
|
||||
}
|
||||
|
||||
// filestream methods
|
||||
|
||||
public FileStream Create ()
|
||||
{
|
||||
return File.Create (FullPath);
|
||||
}
|
||||
|
||||
public FileStream OpenRead ()
|
||||
{
|
||||
return Open (FileMode.Open, FileAccess.Read, FileShare.Read);
|
||||
}
|
||||
|
||||
public FileStream OpenWrite ()
|
||||
{
|
||||
return Open (FileMode.OpenOrCreate, FileAccess.Write);
|
||||
}
|
||||
|
||||
public FileStream Open (FileMode mode)
|
||||
{
|
||||
return Open (mode, FileAccess.ReadWrite);
|
||||
}
|
||||
|
||||
public FileStream Open (FileMode mode, FileAccess access)
|
||||
{
|
||||
return Open (mode, access, FileShare.None);
|
||||
}
|
||||
|
||||
public FileStream Open (FileMode mode, FileAccess access, FileShare share)
|
||||
{
|
||||
return new FileStream (FullPath, mode, access, share);
|
||||
}
|
||||
|
||||
// file methods
|
||||
|
||||
public override void Delete ()
|
||||
{
|
||||
MonoIOError error;
|
||||
|
||||
SecurityManager.EnsureElevatedPermissions (); // this is a no-op outside moonlight
|
||||
|
||||
if (!MonoIO.Exists (FullPath, out error))
|
||||
// a weird MS.NET behaviour
|
||||
return;
|
||||
|
||||
if (MonoIO.ExistsDirectory (FullPath, out error))
|
||||
throw new UnauthorizedAccessException ("Access to the path \"" + FullPath + "\" is denied.");
|
||||
if (!MonoIO.DeleteFile (FullPath, out error))
|
||||
throw MonoIO.GetException (OriginalPath, error);
|
||||
}
|
||||
|
||||
public void MoveTo (string destFileName)
|
||||
{
|
||||
if (destFileName == null)
|
||||
throw new ArgumentNullException ("destFileName");
|
||||
if (destFileName == Name || destFileName == FullName)
|
||||
return;
|
||||
if (!File.Exists (FullPath))
|
||||
throw new FileNotFoundException ();
|
||||
|
||||
File.Move (FullPath, destFileName);
|
||||
this.FullPath = Path.GetFullPath (destFileName);
|
||||
}
|
||||
|
||||
public FileInfo CopyTo (string destFileName)
|
||||
{
|
||||
return CopyTo (destFileName, false);
|
||||
}
|
||||
|
||||
public FileInfo CopyTo (string destFileName, bool overwrite)
|
||||
{
|
||||
if (destFileName == null)
|
||||
throw new ArgumentNullException ("destFileName");
|
||||
if (destFileName.Length == 0)
|
||||
throw new ArgumentException ("An empty file name is not valid.", "destFileName");
|
||||
|
||||
string dest = Path.GetFullPath (destFileName);
|
||||
|
||||
if (overwrite && File.Exists (dest))
|
||||
File.Delete (dest);
|
||||
|
||||
File.Copy (FullPath, dest);
|
||||
|
||||
return new FileInfo (dest);
|
||||
}
|
||||
|
||||
public override string ToString ()
|
||||
{
|
||||
return OriginalPath;
|
||||
}
|
||||
|
||||
#if !MOBILE
|
||||
public FileSecurity GetAccessControl ()
|
||||
{
|
||||
return File.GetAccessControl (FullPath);
|
||||
}
|
||||
|
||||
public FileSecurity GetAccessControl (AccessControlSections includeSections)
|
||||
{
|
||||
return File.GetAccessControl (FullPath, includeSections);
|
||||
}
|
||||
|
||||
[ComVisible (false)]
|
||||
public FileInfo Replace (string destinationFileName,
|
||||
string destinationBackupFileName)
|
||||
{
|
||||
string destinationFullPath = null;
|
||||
if (!Exists)
|
||||
throw new FileNotFoundException ();
|
||||
if (destinationFileName == null)
|
||||
throw new ArgumentNullException ("destinationFileName");
|
||||
if (destinationFileName.Length == 0)
|
||||
throw new ArgumentException ("An empty file name is not valid.", "destinationFileName");
|
||||
|
||||
destinationFullPath = Path.GetFullPath (destinationFileName);
|
||||
|
||||
if (!File.Exists (destinationFullPath))
|
||||
throw new FileNotFoundException ();
|
||||
|
||||
FileAttributes attrs = File.GetAttributes (destinationFullPath);
|
||||
|
||||
if ( (attrs & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
|
||||
throw new UnauthorizedAccessException ();
|
||||
|
||||
if (destinationBackupFileName != null) {
|
||||
if (destinationBackupFileName.Length == 0)
|
||||
throw new ArgumentException ("An empty file name is not valid.", "destinationBackupFileName");
|
||||
File.Copy (destinationFullPath, Path.GetFullPath (destinationBackupFileName), true);
|
||||
}
|
||||
File.Copy (FullPath, destinationFullPath,true);
|
||||
File.Delete (FullPath);
|
||||
return new FileInfo (destinationFullPath);
|
||||
}
|
||||
|
||||
[ComVisible (false)]
|
||||
[MonoLimitation ("We ignore the ignoreMetadataErrors parameter")]
|
||||
public FileInfo Replace (string destinationFileName,
|
||||
string destinationBackupFileName,
|
||||
bool ignoreMetadataErrors)
|
||||
{
|
||||
return Replace (destinationFileName, destinationBackupFileName);
|
||||
}
|
||||
|
||||
public void SetAccessControl (FileSecurity fileSecurity)
|
||||
{
|
||||
File.SetAccessControl (FullPath, fileSecurity);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -639,6 +639,13 @@ namespace System.IO
|
||||
MonoIOError error;
|
||||
|
||||
FlushBuffer ();
|
||||
|
||||
if (CanSeek && !isExposed) {
|
||||
MonoIO.Seek (safeHandle, buf_start, SeekOrigin.Begin, out error);
|
||||
if (error != MonoIOError.ERROR_SUCCESS)
|
||||
throw MonoIO.GetException (GetSecureFileName (name), error);
|
||||
}
|
||||
|
||||
int wcount = count;
|
||||
|
||||
while (wcount > 0){
|
||||
@@ -1037,7 +1044,7 @@ namespace System.IO
|
||||
int wcount = buf_length;
|
||||
int offset = 0;
|
||||
while (wcount > 0){
|
||||
int n = MonoIO.Write (safeHandle, buf, 0, buf_length, out error);
|
||||
int n = MonoIO.Write (safeHandle, buf, offset, buf_length, out error);
|
||||
if (error != MonoIOError.ERROR_SUCCESS) {
|
||||
// don't leak the path information for isolated storage
|
||||
throw MonoIO.GetException (GetSecureFileName (name), error);
|
||||
|
||||
@@ -1,270 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
//
|
||||
// System.IO.FileSystemInfo.cs
|
||||
//
|
||||
// Copyright (C) 2001 Moonlight Enterprises, All Rights Reserved
|
||||
// Copyright 2011 Xamarin Inc (http://www.xamarin.com).
|
||||
//
|
||||
// Author: Jim Richardson, develop@wtfo-guru.com
|
||||
// Dan Lewis (dihlewis@yahoo.co.uk)
|
||||
// Created: Monday, August 13, 2001
|
||||
//
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//
|
||||
// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Security;
|
||||
using System.Security.Permissions;
|
||||
|
||||
namespace System.IO {
|
||||
|
||||
[Serializable]
|
||||
[FileIOPermission (SecurityAction.InheritanceDemand, Unrestricted = true)]
|
||||
[ComVisible (true)]
|
||||
#if NET_2_1
|
||||
public abstract class FileSystemInfo {
|
||||
#else
|
||||
public abstract class FileSystemInfo : MarshalByRefObject, ISerializable {
|
||||
|
||||
#region Implementation of ISerializable
|
||||
|
||||
[ComVisible(false)]
|
||||
public virtual void GetObjectData (SerializationInfo info, StreamingContext context)
|
||||
{
|
||||
info.AddValue ("OriginalPath", OriginalPath, typeof(string));
|
||||
info.AddValue ("FullPath", FullPath, typeof(string));
|
||||
}
|
||||
|
||||
#endregion Implementation of ISerializable
|
||||
#endif
|
||||
// public properties
|
||||
|
||||
public abstract bool Exists { get; }
|
||||
|
||||
public abstract string Name { get; }
|
||||
|
||||
public virtual string FullName {
|
||||
get {
|
||||
return FullPath;
|
||||
}
|
||||
}
|
||||
|
||||
public string Extension {
|
||||
get {
|
||||
return Path.GetExtension (Name);
|
||||
}
|
||||
}
|
||||
|
||||
public FileAttributes Attributes {
|
||||
get {
|
||||
Refresh (false);
|
||||
return stat.Attributes;
|
||||
}
|
||||
|
||||
set {
|
||||
MonoIOError error;
|
||||
|
||||
if (!MonoIO.SetFileAttributes (FullName,
|
||||
value,
|
||||
out error))
|
||||
throw MonoIO.GetException (FullName,
|
||||
error);
|
||||
Refresh (true);
|
||||
}
|
||||
}
|
||||
|
||||
public DateTime CreationTime {
|
||||
get {
|
||||
Refresh (false);
|
||||
return DateTime.FromFileTime (stat.CreationTime);
|
||||
}
|
||||
|
||||
set {
|
||||
SecurityManager.EnsureElevatedPermissions (); // this is a no-op outside moonlight
|
||||
|
||||
long filetime = value.ToFileTime ();
|
||||
|
||||
MonoIOError error;
|
||||
|
||||
if (!MonoIO.SetFileTime (FullName, filetime,
|
||||
-1, -1, out error))
|
||||
throw MonoIO.GetException (FullName,
|
||||
error);
|
||||
Refresh (true);
|
||||
}
|
||||
}
|
||||
|
||||
[ComVisible(false)]
|
||||
public DateTime CreationTimeUtc {
|
||||
get {
|
||||
return CreationTime.ToUniversalTime ();
|
||||
}
|
||||
|
||||
set {
|
||||
CreationTime = value.ToLocalTime ();
|
||||
}
|
||||
}
|
||||
|
||||
public DateTime LastAccessTime {
|
||||
get {
|
||||
Refresh (false);
|
||||
return DateTime.FromFileTime (stat.LastAccessTime);
|
||||
}
|
||||
|
||||
set {
|
||||
SecurityManager.EnsureElevatedPermissions (); // this is a no-op outside moonlight
|
||||
|
||||
long filetime = value.ToFileTime ();
|
||||
|
||||
MonoIOError error;
|
||||
|
||||
if (!MonoIO.SetFileTime (FullName, -1,
|
||||
filetime, -1,
|
||||
out error))
|
||||
throw MonoIO.GetException (FullName,
|
||||
error);
|
||||
Refresh (true);
|
||||
}
|
||||
}
|
||||
|
||||
[ComVisible(false)]
|
||||
public DateTime LastAccessTimeUtc {
|
||||
get {
|
||||
Refresh (false);
|
||||
return LastAccessTime.ToUniversalTime ();
|
||||
}
|
||||
|
||||
set {
|
||||
LastAccessTime = value.ToLocalTime ();
|
||||
}
|
||||
}
|
||||
|
||||
public DateTime LastWriteTime {
|
||||
get {
|
||||
Refresh (false);
|
||||
return DateTime.FromFileTime (stat.LastWriteTime);
|
||||
}
|
||||
|
||||
set {
|
||||
SecurityManager.EnsureElevatedPermissions (); // this is a no-op outside moonlight
|
||||
|
||||
long filetime = value.ToFileTime ();
|
||||
|
||||
MonoIOError error;
|
||||
|
||||
if (!MonoIO.SetFileTime (FullName, -1, -1,
|
||||
filetime, out error))
|
||||
throw MonoIO.GetException (FullName,
|
||||
error);
|
||||
Refresh (true);
|
||||
}
|
||||
}
|
||||
|
||||
[ComVisible(false)]
|
||||
public DateTime LastWriteTimeUtc {
|
||||
get {
|
||||
Refresh (false);
|
||||
return LastWriteTime.ToUniversalTime ();
|
||||
}
|
||||
|
||||
set {
|
||||
LastWriteTime = value.ToLocalTime ();
|
||||
}
|
||||
}
|
||||
|
||||
// public methods
|
||||
|
||||
public abstract void Delete ();
|
||||
|
||||
public void Refresh ()
|
||||
{
|
||||
Refresh (true);
|
||||
}
|
||||
|
||||
// protected
|
||||
|
||||
protected FileSystemInfo ()
|
||||
{
|
||||
this.valid = false;
|
||||
this.FullPath = null;
|
||||
}
|
||||
|
||||
protected FileSystemInfo (SerializationInfo info, StreamingContext context)
|
||||
{
|
||||
if (info == null)
|
||||
{
|
||||
throw new ArgumentNullException("info");
|
||||
}
|
||||
|
||||
FullPath = info.GetString("FullPath");
|
||||
OriginalPath = info.GetString("OriginalPath");
|
||||
}
|
||||
|
||||
protected string FullPath;
|
||||
protected string OriginalPath;
|
||||
|
||||
// internal
|
||||
|
||||
internal void Refresh (bool force)
|
||||
{
|
||||
if (valid && !force)
|
||||
return;
|
||||
|
||||
MonoIOError error;
|
||||
|
||||
MonoIO.GetFileStat (FullName, out stat, out error);
|
||||
/* Don't throw on error here, too much other
|
||||
* stuff relies on it not doing so...
|
||||
*/
|
||||
|
||||
valid = true;
|
||||
|
||||
InternalRefresh ();
|
||||
}
|
||||
|
||||
internal virtual void InternalRefresh ()
|
||||
{
|
||||
}
|
||||
|
||||
internal void CheckPath (string path)
|
||||
{
|
||||
if (path == null)
|
||||
throw new ArgumentNullException ("path");
|
||||
if (path.Length == 0)
|
||||
throw new ArgumentException ("An empty file name is not valid.");
|
||||
if (path.IndexOfAny (Path.InvalidPathChars) != -1)
|
||||
throw new ArgumentException ("Illegal characters in path.");
|
||||
if (Environment.IsRunningOnWindows) {
|
||||
int idx = path.IndexOf (':');
|
||||
if (idx >= 0 && idx != 1)
|
||||
throw new ArgumentException ("path");
|
||||
}
|
||||
}
|
||||
|
||||
internal MonoIOStat stat;
|
||||
internal bool valid;
|
||||
}
|
||||
}
|
||||
@@ -56,7 +56,9 @@ namespace System.IO
|
||||
ERROR_NO_MORE_FILES = 18,
|
||||
/* ERROR_WRITE_PROTECT = 19,
|
||||
ERROR_BAD_UNIT = 20,
|
||||
*/
|
||||
ERROR_NOT_READY = 21,
|
||||
/*
|
||||
ERROR_BAD_COMMAND = 22,
|
||||
ERROR_CRC = 23,
|
||||
ERROR_BAD_LENGTH = 24,
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
//
|
||||
// System.IO.MonoIOStat.cs: Idealized structure for file information.
|
||||
//
|
||||
// Author:
|
||||
// Dan Lewis (dihlewis@yahoo.co.uk)
|
||||
//
|
||||
// (C) 2002
|
||||
//
|
||||
//
|
||||
// System.IO.MonoIOStat.cs: Idealized structure for file information.
|
||||
//
|
||||
// Author:
|
||||
// Dan Lewis (dihlewis@yahoo.co.uk)
|
||||
//
|
||||
// (C) 2002
|
||||
//
|
||||
|
||||
//
|
||||
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
|
||||
@@ -29,16 +29,18 @@
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
using System;
|
||||
|
||||
namespace System.IO
|
||||
{
|
||||
internal struct MonoIOStat {
|
||||
public FileAttributes Attributes;
|
||||
public long Length;
|
||||
public long CreationTime;
|
||||
public long LastAccessTime;
|
||||
public long LastWriteTime;
|
||||
}
|
||||
}
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace System.IO
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct MonoIOStat {
|
||||
public FileAttributes fileAttributes;
|
||||
public long Length;
|
||||
public long CreationTime;
|
||||
public long LastAccessTime;
|
||||
public long LastWriteTime;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -289,6 +289,11 @@ namespace System.IO {
|
||||
return fullpath;
|
||||
}
|
||||
|
||||
internal static String GetFullPathInternal(String path)
|
||||
{
|
||||
return InsecureGetFullPath (path);
|
||||
}
|
||||
|
||||
#if !MOBILE
|
||||
// http://msdn.microsoft.com/en-us/library/windows/desktop/aa364963%28v=vs.85%29.aspx
|
||||
[DllImport("Kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
|
||||
@@ -488,7 +493,7 @@ namespace System.IO {
|
||||
f = new FileStream (path, FileMode.CreateNew, FileAccess.ReadWrite, FileShare.Read,
|
||||
8192, false, (FileOptions) 1);
|
||||
} catch (IOException ex){
|
||||
if (ex.hresult != MonoIO.FileAlreadyExistsHResult || count ++ > 65536)
|
||||
if (ex._HResult != MonoIO.FileAlreadyExistsHResult || count ++ > 65536)
|
||||
throw;
|
||||
} catch (UnauthorizedAccessException ex) {
|
||||
if (count ++ > 65536)
|
||||
@@ -871,5 +876,11 @@ namespace System.IO {
|
||||
throw new ArgumentException (parameterName);
|
||||
}
|
||||
}
|
||||
|
||||
internal static string DirectorySeparatorCharAsString {
|
||||
get {
|
||||
return DirectorySeparatorStr;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user