Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Incorporate feedback comments raised while open sourcing System.IO.IsolatedStorage #4975

Merged
merged 1 commit into from
Dec 15, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@
using System.Collections.Generic;
using System.Security;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Diagnostics.Contracts;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming we aren't using anything from Contracts anymore, this can be removed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes please sort and remove unused. We should make CodeFormatter tool do that :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are using Contract via Contract.EndContractBlock and PureAttribute :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, sounds good to me. How do we feel about removing the EndContractBlock calls? I thought those were only useful if we were using Code Contracts.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my personal opinion, they are not very useful, however, its merits are still under debate (#503 , dotnet/corert#320, dotnet/roslyn#98) and I do see other libraries relying on it. So for now, I don't see any harm in letting them stay.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed I've held back on doing a scrub of all the contract calls for now until we figure out our longer term story around them.

using System.Linq;

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;

Expand All @@ -32,7 +33,7 @@ internal bool Disposed
{
get
{
return m_bDisposed;
return _disposed;
}
}

Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -505,7 +506,7 @@ internal static IsolatedStorageFile GetUserStore()
IsolatedStorageRoot = FetchOrCreateRoot();

IsolatedStorageFile isf = new IsolatedStorageFile();
isf.m_AppFilesPath = IsolatedStorageRoot;
isf._appFilesPath = IsolatedStorageRoot;
return isf;
}

Expand All @@ -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;

Expand All @@ -529,7 +530,7 @@ internal string GetFullPath(string partialPath)

partialPath = partialPath.Substring(i);

return Path.Combine(m_AppFilesPath, partialPath);
return Path.Combine(_appFilesPath, partialPath);
}

/*
Expand All @@ -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
{
Expand Down Expand Up @@ -584,22 +585,22 @@ 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;
}


[SecurityCritical]
internal static Exception GetIsolatedStorageException(string exceptionMsg, Exception rootCause)
{
IsolatedStorageException e = new IsolatedStorageException(exceptionMsg, rootCause);
e.m_UnderlyingException = rootCause;
e._underlyingException = rootCause;
return e;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() { }

Expand Down Expand Up @@ -77,22 +77,22 @@ 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)
{
// 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);
}
Expand All @@ -103,7 +103,7 @@ public override bool CanRead
[Pure]
get
{
return m_fs.CanRead;
return _fs.CanRead;
}
}

Expand All @@ -112,7 +112,7 @@ public override bool CanWrite
[Pure]
get
{
return m_fs.CanWrite;
return _fs.CanWrite;
}
}

Expand All @@ -121,28 +121,28 @@ public override bool CanSeek
[Pure]
get
{
return m_fs.CanSeek;
return _fs.CanSeek;
}
}

public override long Length
{
get
{
return m_fs.Length;
return _fs.Length;
}
}

public override long Position
{
get
{
return m_fs.Position;
return _fs.Position;
}

set
{
m_fs.Position = value;
_fs.Position = value;
}
}

Expand All @@ -151,7 +151,7 @@ public string Name
[SecurityCritical]
get
{
return m_FullPath;
return _fullPath;
}
}

Expand All @@ -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
Expand All @@ -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<int> 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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace System.IO.IsolatedStorage
[SecurityCritical]
internal class IsolatedStorageSecurityState
{
private string m_RootUserDirectory;
private string _rootUserDirectory;

internal static string GetRootUserDirectory()
{
Expand All @@ -27,11 +27,11 @@ private String RootUserDirectory
{
get
{
return m_RootUserDirectory;
return _rootUserDirectory;
}
set
{
m_RootUserDirectory = value;
_rootUserDirectory = value;
}
}

Expand Down