diff options
Diffstat (limited to 'mcs/class/corlib/System.IO')
-rw-r--r-- | mcs/class/corlib/System.IO/ChangeLog | 48 | ||||
-rw-r--r-- | mcs/class/corlib/System.IO/CheckPermission.cs | 2 | ||||
-rw-r--r-- | mcs/class/corlib/System.IO/File.cs | 6 | ||||
-rw-r--r-- | mcs/class/corlib/System.IO/FileInfo.cs | 2 | ||||
-rw-r--r-- | mcs/class/corlib/System.IO/FileStream.cs | 2 | ||||
-rw-r--r-- | mcs/class/corlib/System.IO/MonoIO.cs | 11 | ||||
-rwxr-xr-x | mcs/class/corlib/System.IO/Stream.cs | 1 | ||||
-rw-r--r-- | mcs/class/corlib/System.IO/StreamWriter.cs | 43 | ||||
-rw-r--r-- | mcs/class/corlib/System.IO/UnexceptionalStreamReader.cs | 149 | ||||
-rw-r--r-- | mcs/class/corlib/System.IO/UnexceptionalStreamWriter.cs | 128 |
10 files changed, 376 insertions, 16 deletions
diff --git a/mcs/class/corlib/System.IO/ChangeLog b/mcs/class/corlib/System.IO/ChangeLog index 6818c37ad82..2a98da3be31 100644 --- a/mcs/class/corlib/System.IO/ChangeLog +++ b/mcs/class/corlib/System.IO/ChangeLog @@ -1,3 +1,51 @@ +2004-09-19 Dick Porter <dick@ximian.com> + + * UnexceptionalStreamWriter.cs: + * UnexceptionalStreamReader.cs: Wrappers around StreamWriter and + StreamReader that catch IOException. Used by System.Console so + that graphical applications dont get IO errors when their + stdin/out/err vanishes (ie when they spew debug output.) + +2004-09-04 Gonzalo Paniagua Javier <gonzalo@ximian.com> + + * Stream.cs: Close() does not call Flush(). Fixes bug #65340. + +2004-08-26 Ben Maurer <bmaurer@users.sourceforge.net> + + * StreamWriter.cs: avoid String.ToCharArray for perf. + +2004-08-18 Dick Porter <dick@ximian.com> + + * StreamWriter.cs: Flush the buffer if AutoFlush is set to true. + Fixes bug 63063, patch by Laurent Debacker (debackerl@yahoo.com). + +2004-08-13 Dick Porter <dick@ximian.com> + + * StreamWriter.cs: Allow FileShare.Read access to the underlying + FileStream, to be compatible with MS. Fixes bug 62152. + +2004-07-06 Dick Porter <dick@ximian.com> + + * MonoIO.cs: Add ERROR_INVALID_PARAMETER to the exception list. + Don't blow away the SetFileTime() error before the caller gets to + see it. Part of the bug fix to 60970. + +2004-07-05 Dick Porter <dick@ximian.com> + + * CheckPermission.cs: + * File.cs: + * FileInfo.cs: + * MonoIO.cs: + * FileStream.cs: Give the filename when throwing + FileNotFoundException. Fixes bug 61120, based on patch from + Carlos Alberto Cesario <carloscesario@gmail.com>. + +2004-07-05 Dick Porter <dick@ximian.com> + + * File.cs: File.Move() should check that the destination doesn't + already exist. Fixes bug 60915, patch based on one from Carlos + Alberto Cesario <carloscesario@gmail.com>. + 2004-06-24 Gonzalo Paniagua Javier <gonzalo@ximian.com> * Directory.cs: implemented GetLogicalDrives. diff --git a/mcs/class/corlib/System.IO/CheckPermission.cs b/mcs/class/corlib/System.IO/CheckPermission.cs index 2b31cab7e01..232b1350af4 100644 --- a/mcs/class/corlib/System.IO/CheckPermission.cs +++ b/mcs/class/corlib/System.IO/CheckPermission.cs @@ -102,7 +102,7 @@ namespace System.IO } else { - throw new FileNotFoundException(); + throw new FileNotFoundException("File not found", path); } #endif } diff --git a/mcs/class/corlib/System.IO/File.cs b/mcs/class/corlib/System.IO/File.cs index c45dea6aecb..3dcf8213759 100644 --- a/mcs/class/corlib/System.IO/File.cs +++ b/mcs/class/corlib/System.IO/File.cs @@ -70,7 +70,7 @@ namespace System.IO if (dest.Trim () == "" || dest.IndexOfAny (Path.InvalidPathChars) != -1) throw new ArgumentException ("dest"); if (!Exists (src)) - throw new FileNotFoundException (src + " does not exist"); + throw new FileNotFoundException (src + " does not exist", src); if ((GetAttributes(src) & FileAttributes.Directory) == FileAttributes.Directory){ throw new ArgumentException(src + " is a directory"); @@ -261,9 +261,11 @@ namespace System.IO if (dest.Trim () == "" || dest.IndexOfAny (Path.InvalidPathChars) != -1) throw new ArgumentException ("dest"); if (!MonoIO.Exists (src, out error)) - throw new FileNotFoundException (src + " does not exist"); + throw new FileNotFoundException (src + " does not exist", src); if (MonoIO.ExistsDirectory (dest, out error)) throw new IOException (dest + " is a directory"); + if (MonoIO.Exists (dest, out error)) + throw new IOException (dest + " already exists"); string DirName; DirName = Path.GetDirectoryName(src); diff --git a/mcs/class/corlib/System.IO/FileInfo.cs b/mcs/class/corlib/System.IO/FileInfo.cs index c98cf6feaec..3345f61dc79 100644 --- a/mcs/class/corlib/System.IO/FileInfo.cs +++ b/mcs/class/corlib/System.IO/FileInfo.cs @@ -81,7 +81,7 @@ namespace System.IO { public long Length {
get {
if (!Exists)
- throw new FileNotFoundException ("Could not find file \"" + OriginalPath + "\".");
+ throw new FileNotFoundException ("Could not find file \"" + OriginalPath + "\".", OriginalPath);
return stat.Length;
}
diff --git a/mcs/class/corlib/System.IO/FileStream.cs b/mcs/class/corlib/System.IO/FileStream.cs index 3024bf35d04..01b726a0b92 100644 --- a/mcs/class/corlib/System.IO/FileStream.cs +++ b/mcs/class/corlib/System.IO/FileStream.cs @@ -155,7 +155,7 @@ namespace System.IO if (access == FileAccess.Read && mode != FileMode.Create && mode != FileMode.OpenOrCreate && mode != FileMode.CreateNew && !File.Exists (name)) - throw new FileNotFoundException ("Could not find file \"" + name + "\"."); + throw new FileNotFoundException ("Could not find file \"" + name + "\".", name); if (mode == FileMode.CreateNew) { string dname = Path.GetDirectoryName (name); diff --git a/mcs/class/corlib/System.IO/MonoIO.cs b/mcs/class/corlib/System.IO/MonoIO.cs index 47fd104fdc3..a32e6ed5408 100644 --- a/mcs/class/corlib/System.IO/MonoIO.cs +++ b/mcs/class/corlib/System.IO/MonoIO.cs @@ -63,7 +63,8 @@ namespace System.IO // FIXME: add more exception mappings here case MonoIOError.ERROR_FILE_NOT_FOUND: message = String.Format ("Could not find file \"{0}\"", path); - return new FileNotFoundException (message); + return new FileNotFoundException (message, + path); case MonoIOError.ERROR_PATH_NOT_FOUND: message = String.Format ("Could not find a part of the path \"{0}\"", path); @@ -81,6 +82,10 @@ namespace System.IO message = String.Format ("Path is too long. Path: {0}", path); return new PathTooLongException (message); + case MonoIOError.ERROR_INVALID_PARAMETER: + message = String.Format ("Invalid parameter"); + return new IOException (message); + default: message = String.Format ("Win32 IO returned {0}. Path: {1}", error, path); return new IOException (message); @@ -304,7 +309,9 @@ namespace System.IO result = SetFileTime (handle, creation_time, last_access_time, last_write_time, out error); - Close (handle, out error); + + MonoIOError ignore_error; + Close (handle, out ignore_error); return result; } diff --git a/mcs/class/corlib/System.IO/Stream.cs b/mcs/class/corlib/System.IO/Stream.cs index 04884fb5e3d..6623da319a1 100755 --- a/mcs/class/corlib/System.IO/Stream.cs +++ b/mcs/class/corlib/System.IO/Stream.cs @@ -77,7 +77,6 @@ namespace System.IO public virtual void Close () { - Flush (); } void IDisposable.Dispose () diff --git a/mcs/class/corlib/System.IO/StreamWriter.cs b/mcs/class/corlib/System.IO/StreamWriter.cs index 4c51d0269be..1799d74e6e6 100644 --- a/mcs/class/corlib/System.IO/StreamWriter.cs +++ b/mcs/class/corlib/System.IO/StreamWriter.cs @@ -123,7 +123,7 @@ namespace System.IO { else
mode = FileMode.Create;
- internalStream = new FileStream (path, mode, FileAccess.Write);
+ internalStream = new FileStream (path, mode, FileAccess.Write, FileShare.Read);
if (append)
internalStream.Position = internalStream.Length;
@@ -137,12 +137,16 @@ namespace System.IO { get {
return iflush;
}
- set {
- if (DisposedAlready)
- throw new ObjectDisposedException("StreamWriter");
- iflush = value;
- }
- }
+ set { + if (DisposedAlready) + throw new ObjectDisposedException("StreamWriter"); + iflush = value; + + if (iflush) { + Flush (); + } + } + } public virtual Stream BaseStream {
get {
@@ -245,6 +249,28 @@ namespace System.IO { index += todo;
decode_pos += todo;
}
+ } + + void LowLevelWrite (string s) + { + int count = s.Length; + int index = 0; + while (count > 0) { + int todo = decode_buf.Length - decode_pos; + if (todo == 0) { + Decode (); + todo = decode_buf.Length; + } + if (todo > count) + todo = count; + + for (int i = 0; i < todo; i ++) + decode_buf [i + decode_pos] = s [i + index]; + + count -= todo; + index += todo; + decode_pos += todo; + } }
public override void Write (char value)
@@ -278,7 +304,8 @@ namespace System.IO { throw new ObjectDisposedException("StreamWriter");
if (value != null)
- LowLevelWrite (value.ToCharArray (), 0, value.Length);
+ LowLevelWrite (value); +
if (iflush)
Flush ();
}
diff --git a/mcs/class/corlib/System.IO/UnexceptionalStreamReader.cs b/mcs/class/corlib/System.IO/UnexceptionalStreamReader.cs new file mode 100644 index 00000000000..7c527459204 --- /dev/null +++ b/mcs/class/corlib/System.IO/UnexceptionalStreamReader.cs @@ -0,0 +1,149 @@ +// +// System.IO.UnexceptionalStreamReader.cs +// +// Authors: +// Dietmar Maurer (dietmar@ximian.com) +// Miguel de Icaza (miguel@ximian.com) +// Dick Porter (dick@ximian.com) +// +// (C) Ximian, Inc. http://www.ximian.com +// Copyright (C) 2004 Novell (http://www.novell.com) +// + +// +// Copyright (C) 2004 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. +// + + +// This is a wrapper around StreamReader used by System.Console that +// catches IOException so that graphical applications don't suddenly +// get IO errors when their terminal vanishes. See +// UnexceptionalStreamWriter too. + +using System; +using System.Text; +using System.Runtime.InteropServices; + +namespace System.IO { + internal class UnexceptionalStreamReader : StreamReader { + public UnexceptionalStreamReader(Stream stream) + : base (stream) + { + } + + public UnexceptionalStreamReader(Stream stream, bool detect_encoding_from_bytemarks) + : base (stream, detect_encoding_from_bytemarks) + { + } + + public UnexceptionalStreamReader(Stream stream, Encoding encoding) + : base (stream, encoding) + { + } + + public UnexceptionalStreamReader(Stream stream, Encoding encoding, bool detect_encoding_from_bytemarks) + : base (stream, encoding, detect_encoding_from_bytemarks) + { + } + + public UnexceptionalStreamReader(Stream stream, Encoding encoding, bool detect_encoding_from_bytemarks, int buffer_size) + : base (stream, encoding, detect_encoding_from_bytemarks, buffer_size) + { + } + + public UnexceptionalStreamReader(string path) + : base (path) + { + } + + public UnexceptionalStreamReader(string path, bool detect_encoding_from_bytemarks) + : base (path, detect_encoding_from_bytemarks) + { + } + + public UnexceptionalStreamReader(string path, Encoding encoding) + : base (path, encoding) + { + } + + public UnexceptionalStreamReader(string path, Encoding encoding, bool detect_encoding_from_bytemarks) + : base (path, encoding, detect_encoding_from_bytemarks) + { + } + + public UnexceptionalStreamReader(string path, Encoding encoding, bool detect_encoding_from_bytemarks, int buffer_size) + : base (path, encoding, detect_encoding_from_bytemarks, buffer_size) + { + } + + public override int Peek () + { + try { + return(base.Peek ()); + } catch (IOException) { + } + + return(-1); + } + + public override int Read () + { + try { + return(base.Read ()); + } catch (IOException) { + } + + return(-1); + } + + public override int Read ([In, Out] char[] dest_buffer, + int index, int count) + { + try { + return(base.Read (dest_buffer, index, count)); + } catch (IOException) { + } + + return(0); + } + + public override string ReadLine() + { + try { + return(base.ReadLine ()); + } catch (IOException) { + } + + return(null); + } + + public override string ReadToEnd() + { + try { + return(base.ReadToEnd ()); + } catch (IOException) { + } + + return(null); + } + } +} diff --git a/mcs/class/corlib/System.IO/UnexceptionalStreamWriter.cs b/mcs/class/corlib/System.IO/UnexceptionalStreamWriter.cs new file mode 100644 index 00000000000..db9fd5842e7 --- /dev/null +++ b/mcs/class/corlib/System.IO/UnexceptionalStreamWriter.cs @@ -0,0 +1,128 @@ +// +// System.IO.StreamWriter.cs +// +// Authors: +// Dietmar Maurer (dietmar@ximian.com) +// Paolo Molaro (lupus@ximian.com) +// Dick Porter (dick@ximian.com) +// +// (C) Ximian, Inc. http://www.ximian.com +// + +// +// Copyright (C) 2004 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. +// + + +// This is a wrapper around StreamWriter used by System.Console that +// catches IOException so that graphical applications don't suddenly +// get IO errors when their terminal vanishes (ie when they spew debug +// output.) See UnexceptionalStreamReader too. + +using System.Text; +using System; + +namespace System.IO { + internal class UnexceptionalStreamWriter: StreamWriter { + public UnexceptionalStreamWriter (Stream stream) + : base (stream) + { + } + + public UnexceptionalStreamWriter (Stream stream, + Encoding encoding) + : base (stream, encoding) + { + } + + public UnexceptionalStreamWriter (Stream stream, + Encoding encoding, + int bufferSize) + : base (stream, encoding, bufferSize) + { + } + + public UnexceptionalStreamWriter (string path) + : base (path) + { + } + + public UnexceptionalStreamWriter (string path, bool append) + : base (path, append) + { + } + + public UnexceptionalStreamWriter (string path, bool append, + Encoding encoding) + : base (path, append, encoding) + { + } + + public UnexceptionalStreamWriter (string path, bool append, + Encoding encoding, + int bufferSize) + : base (path, append, encoding, bufferSize) + { + } + + public override void Flush () + { + try { + base.Flush (); + } catch (IOException) { + } + } + + public override void Write (char[] buffer, int index, + int count) + { + try { + base.Write (buffer, index, count); + } catch (IOException) { + } + } + + public override void Write (char value) + { + try { + base.Write (value); + } catch (IOException) { + } + } + + public override void Write (char[] value) + { + try { + base.Write (value); + } catch (IOException) { + } + } + + public override void Write (string value) + { + try { + base.Write (value); + } catch (IOException) { + } + } + } +} |