From e45b6b3ef5ab6a9b887656531b60d4c4f3a76d96 Mon Sep 17 00:00:00 2001 From: Pallavi Taneja Date: Mon, 14 Dec 2015 11:30:13 -0800 Subject: [PATCH] Fix Issue#4954 --- .../IsolatedStorageException.cs | 4 +- .../IO/IsolatedStorage/IsolatedStorageFile.cs | 35 +++++------ .../IsolatedStorageFileStream.cs | 58 +++++++++---------- .../IsolatedStorageSecurityState.cs | 6 +- 4 files changed, 53 insertions(+), 50 deletions(-) diff --git a/src/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/IsolatedStorageException.cs b/src/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/IsolatedStorageException.cs index 4feeec8165a2..037f757b79a5 100644 --- a/src/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/IsolatedStorageException.cs +++ b/src/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/IsolatedStorageException.cs @@ -9,7 +9,9 @@ public class IsolatedStorageException : Exception { private const int COR_E_ISOSTORE = unchecked((int)0x80131450); - internal Exception m_UnderlyingException; + // All the exceptions from IsolatedStorage are wrapped as IsolatedStorageException, + // this field is used to provide the underlying exception under debugger. + internal Exception _underlyingException; public IsolatedStorageException() : base(SR.IsolatedStorage_Exception) diff --git a/src/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/IsolatedStorageFile.cs b/src/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/IsolatedStorageFile.cs index 30539d3837d1..70896af17abe 100644 --- a/src/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/IsolatedStorageFile.cs +++ b/src/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/IsolatedStorageFile.cs @@ -7,6 +7,7 @@ using System.Collections.Generic; using System.Security; using System.Runtime.InteropServices; +using System.Diagnostics; using System.Diagnostics.Contracts; using System.Linq; @@ -14,12 +15,12 @@ namespace System.IO.IsolatedStorage { public sealed class IsolatedStorageFile : IDisposable { - private string m_AppFilesPath; + private string _appFilesPath; - private bool m_bDisposed; - private bool m_closed; + private bool _disposed; + private bool _closed; - private object m_internalLock = new object(); + private readonly object _internalLock = new object(); private static string s_RootFromHost; private static string s_IsolatedStorageRoot; @@ -32,7 +33,7 @@ internal bool Disposed { get { - return m_bDisposed; + return _disposed; } } @@ -78,11 +79,11 @@ internal bool IsDeleted internal void Close() { - lock (m_internalLock) + lock (_internalLock) { - if (!m_closed) + if (!_closed) { - m_closed = true; + _closed = true; GC.SuppressFinalize(this); } } @@ -206,7 +207,7 @@ public String[] GetFileNames(String searchPattern) { // FileSystem APIs return the complete path of the matching files however Iso store only provided the FileName // and hid the IsoStore root. Hence we find all the matching files from the fileSystem and simply return the fileNames. - return Directory.EnumerateFiles(m_AppFilesPath, searchPattern).Select(f => Path.GetFileName(f)).ToArray(); + return Directory.EnumerateFiles(_appFilesPath, searchPattern).Select(f => Path.GetFileName(f)).ToArray(); } catch (UnauthorizedAccessException e) { @@ -235,7 +236,7 @@ public String[] GetDirectoryNames(String searchPattern) { // FileSystem APIs return the complete path of the matching directories however Iso store only provided the directory name // and hid the IsoStore root. Hence we find all the matching directories from the fileSystem and simply return their names. - return Directory.EnumerateDirectories(m_AppFilesPath, searchPattern).Select(m => m.Substring(Path.GetDirectoryName(m).Length + 1)).ToArray(); + return Directory.EnumerateDirectories(_appFilesPath, searchPattern).Select(m => m.Substring(Path.GetDirectoryName(m).Length + 1)).ToArray(); } catch (UnauthorizedAccessException e) { @@ -505,7 +506,7 @@ internal static IsolatedStorageFile GetUserStore() IsolatedStorageRoot = FetchOrCreateRoot(); IsolatedStorageFile isf = new IsolatedStorageFile(); - isf.m_AppFilesPath = IsolatedStorageRoot; + isf._appFilesPath = IsolatedStorageRoot; return isf; } @@ -514,7 +515,7 @@ internal static IsolatedStorageFile GetUserStore() */ internal string GetFullPath(string partialPath) { - Contract.Assert(partialPath != null, "partialPath should be non null"); + Debug.Assert(partialPath != null, "partialPath should be non null"); int i; @@ -529,7 +530,7 @@ internal string GetFullPath(string partialPath) partialPath = partialPath.Substring(i); - return Path.Combine(m_AppFilesPath, partialPath); + return Path.Combine(_appFilesPath, partialPath); } /* @@ -539,7 +540,7 @@ private static void CreatePathPrefixIfNeeded(string path) { string root = Path.GetPathRoot(path); - Contract.Assert(!String.IsNullOrEmpty(root), "Path.GetPathRoot returned null or empty for: " + path); + Debug.Assert(!String.IsNullOrEmpty(root), "Path.GetPathRoot returned null or empty for: " + path); try { @@ -584,14 +585,14 @@ internal void EnsureStoreIsValid() throw new IsolatedStorageException(SR.IsolatedStorage_StoreNotOpen); } - if (m_closed) + if (_closed) throw new InvalidOperationException(SR.IsolatedStorage_StoreNotOpen); } public void Dispose() { Close(); - m_bDisposed = true; + _disposed = true; } @@ -599,7 +600,7 @@ public void Dispose() internal static Exception GetIsolatedStorageException(string exceptionMsg, Exception rootCause) { IsolatedStorageException e = new IsolatedStorageException(exceptionMsg, rootCause); - e.m_UnderlyingException = rootCause; + e._underlyingException = rootCause; return e; } } diff --git a/src/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/IsolatedStorageFileStream.cs b/src/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/IsolatedStorageFileStream.cs index 5e1c1803c867..1ddb1f87635a 100644 --- a/src/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/IsolatedStorageFileStream.cs +++ b/src/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/IsolatedStorageFileStream.cs @@ -15,10 +15,10 @@ public class IsolatedStorageFileStream : Stream { private const String s_BackSlash = "\\"; - private FileStream m_fs; - private IsolatedStorageFile m_isf; - private String m_GivenPath; - private String m_FullPath; + private FileStream _fs; + private IsolatedStorageFile _isf; + private String _givenPath; + private String _fullPath; private IsolatedStorageFileStream() { } @@ -77,14 +77,14 @@ public IsolatedStorageFileStream(String path, FileMode mode, throw new ArgumentException(SR.IsolatedStorage_FileOpenMode); } - m_isf = isf; - m_GivenPath = path; - m_FullPath = m_isf.GetFullPath(m_GivenPath); + _isf = isf; + _givenPath = path; + _fullPath = _isf.GetFullPath(_givenPath); try { - m_fs = new - FileStream(m_FullPath, mode, access, share, bufferSize, + _fs = new + FileStream(_fullPath, mode, access, share, bufferSize, FileOptions.None); } catch (Exception e) @@ -92,7 +92,7 @@ public IsolatedStorageFileStream(String path, FileMode mode, // Exception message might leak the IsolatedStorage path. The desktop prevented this by calling an // internal API which made sure that the exception message was scrubbed. However since the innerException // is never returned to the user(GetIsolatedStorageException() does not populate the innerexception - // in retail bits we leak the path only under the debugger via IsolatedStorageException.m_underlyingException which + // in retail bits we leak the path only under the debugger via IsolatedStorageException._underlyingException which // they can any way look at via IsolatedStorageFile instance as well. throw IsolatedStorageFile.GetIsolatedStorageException("IsolatedStorage_Operation_ISFS", e); } @@ -103,7 +103,7 @@ public override bool CanRead [Pure] get { - return m_fs.CanRead; + return _fs.CanRead; } } @@ -112,7 +112,7 @@ public override bool CanWrite [Pure] get { - return m_fs.CanWrite; + return _fs.CanWrite; } } @@ -121,7 +121,7 @@ public override bool CanSeek [Pure] get { - return m_fs.CanSeek; + return _fs.CanSeek; } } @@ -129,7 +129,7 @@ public override long Length { get { - return m_fs.Length; + return _fs.Length; } } @@ -137,12 +137,12 @@ public override long Position { get { - return m_fs.Position; + return _fs.Position; } set { - m_fs.Position = value; + _fs.Position = value; } } @@ -151,7 +151,7 @@ public string Name [SecurityCritical] get { - return m_FullPath; + return _fullPath; } } @@ -161,8 +161,8 @@ protected override void Dispose(bool disposing) { if (disposing) { - if (m_fs != null) - m_fs.Dispose(); + if (_fs != null) + _fs.Dispose(); } } finally @@ -173,54 +173,54 @@ protected override void Dispose(bool disposing) public override void Flush() { - m_fs.Flush(); + _fs.Flush(); } public override Task FlushAsync(CancellationToken cancellationToken) { - return m_fs.FlushAsync(); + return _fs.FlushAsync(); } public override void SetLength(long value) { - m_fs.SetLength(value); + _fs.SetLength(value); } public override int Read(byte[] buffer, int offset, int count) { - return m_fs.Read(buffer, offset, count); + return _fs.Read(buffer, offset, count); } public override Task ReadAsync(byte[] buffer, int offset, int count, Threading.CancellationToken cancellationToken) { - return m_fs.ReadAsync(buffer, offset, count, cancellationToken); + return _fs.ReadAsync(buffer, offset, count, cancellationToken); } public override int ReadByte() { - return m_fs.ReadByte(); + return _fs.ReadByte(); } public override long Seek(long offset, SeekOrigin origin) { // Desktop implementation of IsolatedStorage ensures that in case the size is increased the new memory is zero'ed out. // However in this implementation we simply call the FileStream.Seek APIs which have an undefined behavior. - return m_fs.Seek(offset, origin); + return _fs.Seek(offset, origin); } public override void Write(byte[] buffer, int offset, int count) { - m_fs.Write(buffer, offset, count); + _fs.Write(buffer, offset, count); } public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) { - return m_fs.WriteAsync(buffer, offset, count, cancellationToken); + return _fs.WriteAsync(buffer, offset, count, cancellationToken); } public override void WriteByte(byte value) { - m_fs.WriteByte(value); + _fs.WriteByte(value); } } } diff --git a/src/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/IsolatedStorageSecurityState.cs b/src/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/IsolatedStorageSecurityState.cs index a4fc07491b61..12def8c51cb1 100644 --- a/src/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/IsolatedStorageSecurityState.cs +++ b/src/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/IsolatedStorageSecurityState.cs @@ -9,7 +9,7 @@ namespace System.IO.IsolatedStorage [SecurityCritical] internal class IsolatedStorageSecurityState { - private string m_RootUserDirectory; + private string _rootUserDirectory; internal static string GetRootUserDirectory() { @@ -27,11 +27,11 @@ private String RootUserDirectory { get { - return m_RootUserDirectory; + return _rootUserDirectory; } set { - m_RootUserDirectory = value; + _rootUserDirectory = value; } }