Skip to content

Commit

Permalink
minor changes to consisntely use Remove rather than delete
Browse files Browse the repository at this point in the history
  • Loading branch information
activescott committed May 22, 2016
1 parent 5d2a888 commit c02e180
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ This is a library for dealing with File I/O on .NET that overcomes some limitati

It was created to factor out some of the file-system specific features that have built up in the [LessMSI project](https://github.com/activescott/lessmsi).


Goals
========
* Support File I/O operations on Windows that .NET's System.IO libraries fail to support such as long paths (those longer than 260 characters).
* Provide a basis for platform independent file system access across both Windows and Unix-like systems such as Linux and Mac OSX, and potentially others (cloud file storage?).


Concepts & Usage
========
Two concepts are necessary to use the library `FileSystem` and `Path`. The static `FileSystem` class is a static class that contains all of the operations available on the `FileSystem`. Any operation that has a path argument, such as `FileSystem.CreateDirectory`, accepts paths as strongly typed `Path` objects rather than strings. For example,
Expand All @@ -20,10 +22,11 @@ Having paths strongly typed rather than strings forces the caller to be more exp

new Path(@"c:\src\\lessmsi") == new Path(@"c:\src\lessmsi") // true

`Path` has some handy shortcuts on it too such as Remove (delete) that calls back into the FileSystem to remove the file or directory at the current path:
`Path` has some handy shortcuts on it too such as Exists that calls back into the FileSystem to determine if the file or directory at the current path already exists.
These methods also provides some compatibility with existing code using System.IO.FileInfo or System.IO.DirectoryInfo so that in many cases you can replace usage of System.IO.FileInfo/DirectoryInfo with LessIO.Path.

Path destDir = new Path(@"c:\src\lessmsi");
destDir.Remove();
Console.WriteLine(destDir.Exists);

`Path` also offers some of the commonly used static methods on System.IO.Path to make the type relatively compatible with existing code using System.IO.Path. For example, `Combine` and `GetFileName` are available to make porting System.IO code easier:

Expand All @@ -34,3 +37,10 @@ Having paths strongly typed rather than strings forces the caller to be more exp
Platform Independence
========
The current implementation supports Win32 via the [Win32FileSystemStrategy.cs](https://github.com/activescott/LessIO/blob/master/src/LessIO/Strategies/Win32/Win32FileSystemStrategy.cs). However, adding support for another file system such as a Unixy file system could be done by implementing the ~10 methods on a class derived from [FileSystemStrategy](https://github.com/activescott/LessIO/blob/master/src/LessIO/Strategies/FileSystemStrategy.cs) and then updating the implementation of [FileSystem.LazyStrategy](https://github.com/activescott/LessIO/blob/master/src/LessIO/FileSystem.cs).


Contributing
========
We accept pull requests! I think this is a sound basis, but obviously there are many improvements that could be made such as [improving platform independence by adding a new FileSystemStrategy](#platform-independence) or adding more static methods to [Path](https://github.com/activescott/LessIO/blob/master/src/LessIO/Path.cs) from System.IO.FileInfo/DirectoryInfo to make it easier to port System.IO code over to this library. There might also be some important methods missing on [FileSystem](https://github.com/activescott/LessIO/blob/master/src/LessIO/FileSystem.cs) as I just added the operations that [LessMSI](https://github.com/activescott/LessMSI) already uses which I imagine is fairly extensive but maybe not comprehensive.

Please do make sure that existing tests pass and please add new ones for the new features you write.
15 changes: 13 additions & 2 deletions src/LessIO/FileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static void CreateDirectory(Path path)
}

/// <summary>
/// Deletes an existing empty directory.
/// Removes/deletes an existing empty directory.
/// See https://msdn.microsoft.com/en-us/library/windows/desktop/aa365488%28v=vs.85%29.aspx
/// </summary>
/// <param name="path"></param>
Expand All @@ -71,7 +71,7 @@ public static void RemoveDirectory(Path path)
}

/// <summary>
/// Deletes an existing empty directory.
/// Removes/deletes an existing directory.
/// See https://msdn.microsoft.com/en-us/library/windows/desktop/aa365488%28v=vs.85%29.aspx
/// </summary>
/// <param name="path">The path to the directory to remove.</param>
Expand All @@ -97,6 +97,17 @@ public static void RemoveFile(Path path, bool forcefully)
Strategy.RemoveFile(path, forcefully);
}

/// <summary>
/// Removes/deletes an existing file.
/// To remove a directory see <see cref="RemoveDirectory"/>.
/// https://msdn.microsoft.com/en-us/library/windows/desktop/aa363915%28v=vs.85%29.aspx
/// </summary>
/// <param name="path">The file to remove.</param>
public static void RemoveFile(Path path)
{
Strategy.RemoveFile(path, false);
}

/// <summary>
/// Copies the specified existing file to a new location.
/// Will throw an exception if the destination file already exists.
Expand Down
11 changes: 1 addition & 10 deletions src/LessIO/Path.cs
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ public Path Parent
}

/// <summary>
/// Indicates if the file or directory at the specified path exists.
/// For code compatibility with <see cref="System.IO.FileSystemInfo.Exists"/>.
/// </summary>
public bool Exists
Expand Down Expand Up @@ -381,16 +382,6 @@ public bool IsPathRooted
}
}



/// <summary>
/// For code compatibility with <see cref="System.IO.FileSystemInfo.Delete()"/>
/// </summary>
public void Delete()
{
FileSystem.RemoveFile(this, false);
}

/// <summary>
/// For code compatibility with <see cref="System.IO.FileInfo.CreateText()"/>
/// </summary>
Expand Down

0 comments on commit c02e180

Please sign in to comment.