Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add nativefilestream and several new methods to File and FileStream #98

Merged
merged 73 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
412c8f7
Improvement in Path
josesimoes Apr 5, 2024
540d876
Bump native assembly version
josesimoes Apr 10, 2024
db788cb
More work on FileStream and helper classes
josesimoes Apr 10, 2024
eea3e6e
Remove GetLastWriteTime tests
josesimoes Apr 11, 2024
22baeaa
Remove private reference of several references
josesimoes Apr 11, 2024
8cb6dc9
Replace empty string with constant from string class
josesimoes Apr 11, 2024
3298aca
Complete rework to use new native API
josesimoes Apr 11, 2024
eb66f84
Bump native assembly version
josesimoes Apr 11, 2024
49fd8eb
Remove obsolete method
josesimoes Apr 11, 2024
1fd1f74
Replace empty attribute with constant
josesimoes Apr 11, 2024
7a677d0
Removing private constructor
josesimoes Apr 11, 2024
3097d2c
Remove duplicated namespace
josesimoes Apr 11, 2024
96037f9
Remove unused usings
josesimoes Apr 11, 2024
679d146
Remove native call for SetAttributes
josesimoes Apr 15, 2024
1bdef5f
Replace with existing constant
josesimoes Apr 15, 2024
06f9756
Remove as already implemented in NativeIO
josesimoes Apr 15, 2024
d4d303a
Simplifications following code review
josesimoes Apr 16, 2024
fb1c584
Add comment about sync with native code
josesimoes Apr 16, 2024
ffffb9f
Fix exception error code
josesimoes Apr 16, 2024
d77d1db
Fix formatting
josesimoes Apr 16, 2024
d9024cf
Revert wrong exception code being set
josesimoes Apr 17, 2024
7abfca1
Fix typo
josesimoes Apr 17, 2024
5b6602a
Fix Path and its Unit Tests
josesimoes Apr 17, 2024
c53db1b
Rework implementation of Read and WriteAllBytes
josesimoes Apr 18, 2024
9881614
Move setting attributes on file copy
josesimoes Apr 18, 2024
cdc5bfc
Merge branch 'main' of https://github.com/nanoframework/System.IO.Fil…
josesimoes Apr 18, 2024
d13dc5e
Enable proper implementation of GetFullPath
josesimoes Apr 18, 2024
4d3bbc7
Fix file Move
josesimoes Apr 22, 2024
7a0e6a0
Use implicit type in couple of streams for readability
josesimoes Apr 22, 2024
178b6d8
Fix GetFullPath unit test
josesimoes Apr 22, 2024
3b6a638
Fix File.Move
josesimoes Apr 23, 2024
33cd164
Code style fixes
josesimoes Apr 23, 2024
8c65f14
Massive rework on File unit tests
josesimoes Apr 23, 2024
664f9aa
Fix class name
josesimoes Apr 23, 2024
6d6c5a0
Add Unit Tests for Directory class
josesimoes Apr 24, 2024
7a61212
Merge branch 'main' of https://github.com/nanoframework/System.IO.Fil…
josesimoes May 7, 2024
81db319
Fix DirectoryInfo.Parent
josesimoes May 7, 2024
2577b20
Code style fixes
josesimoes May 7, 2024
15314b7
Add support for recursive directory deletion
josesimoes May 10, 2024
c8e04ca
Major rework and improvement of directory Unit Tests
josesimoes May 10, 2024
a525179
Rework Path unit tests to use root as class constant
josesimoes May 10, 2024
99f9f79
Fix NormalizeDirectorySeparators
josesimoes May 10, 2024
20a5454
Improvements and fixes for Path unit tests
josesimoes May 10, 2024
acab8e5
Remove managed implementation of native FindFile
josesimoes May 13, 2024
146b405
Merge branch 'main' of https://github.com/nanoframework/System.IO.Fil…
josesimoes May 23, 2024
f902052
Add MountRemovableVolumes
josesimoes May 24, 2024
310030a
Add missing comment for parameter
josesimoes May 24, 2024
e239a60
Fix unit test with directory creation
josesimoes May 24, 2024
29bc90a
Various fixes in unit tests
josesimoes Jun 3, 2024
be556af
Add new test for large file content
josesimoes Jun 3, 2024
3c6d6fc
Fix fixed driver letter in test
josesimoes Jun 4, 2024
9c7ff06
Fix NormalizeDirectorySeparators
josesimoes Jun 6, 2024
71bf7b7
Add assert skip to all Unit tests related with UNC
josesimoes Jun 7, 2024
da25bc0
Extract unit test configs to base class
josesimoes Jun 7, 2024
87b2026
Rework StorageEventManager
josesimoes Jun 7, 2024
d888b16
Uncomment skip assert as the unit test can't run on the pipeline
josesimoes Jun 7, 2024
a12d3a2
Merge branch 'main' of https://github.com/nanoframework/System.IO.Fil…
josesimoes Jun 7, 2024
1f76181
Refactor FileStream constructor
josesimoes Jun 7, 2024
503c4d7
Various fixes from sonarcloud analysis
josesimoes Jun 7, 2024
6d59700
Joined two test methods as their were the same
josesimoes Jun 7, 2024
724d34a
Rename method for consistency
josesimoes Jun 7, 2024
0bffc42
Replace params from int to enums to improve code readability
josesimoes Jun 7, 2024
e113b3d
Change visibility per sonarlint advice
josesimoes Jun 7, 2024
ff143af
Add implementation for Format API
josesimoes Jun 7, 2024
f3635e0
Refactors and fixes from sonarcloud analysis
josesimoes Jun 7, 2024
c475575
Update test framework nuget
josesimoes Jun 12, 2024
55dbf1d
Improve computation of path separator
josesimoes Jul 22, 2024
916cb77
Improvements in setting up some tests
josesimoes Jul 22, 2024
1c32871
General improvements in GetFiles
josesimoes Jul 23, 2024
81015eb
Fix test setting up
josesimoes Jul 23, 2024
2c0451e
Move all common setup code to tests base class
josesimoes Jul 23, 2024
28d1849
Merge branch 'main' of https://github.com/nanoframework/System.IO.Fil…
josesimoes Jul 23, 2024
104613c
Set test config default to allow running on virtual device
josesimoes Jul 23, 2024
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
22 changes: 0 additions & 22 deletions System.IO.FileSystem.UnitTests/FileUnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,28 +262,6 @@ public void GetAttributes_throws_if_file_does_not_exist()
});
}

[TestMethod]
public void GetLastWriteTime_returns_DateTime()
{
ExecuteTestAndTearDown(() =>
{
CreateFile(Source, BinaryContent);

var actual = File.GetLastWriteTime(Source);

Assert.IsTrue(actual != default, "Failed to get last write time.");
});
}

[TestMethod]
public void GetLastWriteTime_throws_if_path_does_not_exist()
{
ExecuteTestAndTearDown(() =>
{
Assert.ThrowsException(typeof(IOException), () => { File.GetLastWriteTime(Source); });
});
}

[TestMethod]
public void Move_moves_to_destination()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,12 @@
</Reference>
<Reference Include="nanoFramework.TestFramework, Version=2.1.94.0, Culture=neutral, PublicKeyToken=c07d481e9758c731">
<HintPath>..\packages\nanoFramework.TestFramework.2.1.94\lib\nanoFramework.TestFramework.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="nanoFramework.UnitTestLauncher, Version=0.0.0.0, Culture=neutral, PublicKeyToken=c07d481e9758c731">
<HintPath>..\packages\nanoFramework.TestFramework.2.1.94\lib\nanoFramework.UnitTestLauncher.exe</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.IO.Streams, Version=1.1.59.0, Culture=neutral, PublicKeyToken=c07d481e9758c731">
<HintPath>..\packages\nanoFramework.System.IO.Streams.1.1.59\lib\System.IO.Streams.dll</HintPath>
<Private>True</Private>
</Reference>
</ItemGroup>
<Import Project="$(NanoFrameworkProjectSystemPath)NFProjectSystem.CSharp.targets" Condition="Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.CSharp.targets')" />
Expand Down
304 changes: 226 additions & 78 deletions System.IO.FileSystem/Directory.cs

Large diffs are not rendered by default.

179 changes: 179 additions & 0 deletions System.IO.FileSystem/DirectoryInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
//
// Copyright (c) .NET Foundation and Contributors
// See LICENSE file in the project root for full license information.
//

namespace System.IO
{
/// <summary>
/// Exposes instance methods for creating, moving, and enumerating through directories and subdirectories. This class cannot be inherited.
/// </summary>
public sealed class DirectoryInfo : FileSystemInfo
{
/// <summary>
/// Gets the name of this <see cref="DirectoryInfo"/> instance.
/// </summary>
public override string Name
{
get
{
return Path.GetFileName(_fullPath);
}
}

/// <inheritdoc/>
public override bool Exists
{
get
{
return Directory.Exists(_fullPath);
}
}

/// <summary>
/// Gets the root portion of the directory.
/// </summary>
/// <value>An object that represents the root of the directory.</value>
public DirectoryInfo Root
{
get
{
return new DirectoryInfo(Path.GetPathRoot(_fullPath));
}
}

/// <summary>
/// Gets the parent directory of a specified subdirectory.
/// </summary>
public DirectoryInfo Parent
{
get
{
string parentDirPath = Path.GetDirectoryName(_fullPath);

if (parentDirPath == null)
{
return null;
}

return new DirectoryInfo(parentDirPath);
}
}

/// <summary>
/// Initializes a new instance of the <see cref="DirectoryInfo"/> class on the specified path.
/// </summary>
/// <param name="path"></param>
public DirectoryInfo(string path)
{
// path validation happening in the call
_fullPath = Path.GetFullPath(path);
}

/// <summary>
/// Creates a directory.
/// </summary>
public void Create()
{
Directory.CreateDirectory(_fullPath);
}

/// <summary>
/// Creates a subdirectory or subdirectories on the specified path. The specified path can be relative to this instance of the <see cref="DirectoryInfo"/> class.
/// </summary>
/// <param name="path"></param>
/// <returns></returns>
public DirectoryInfo CreateSubdirectory(string path)
{
// path validatation happening in the call
string subDirPath = Path.Combine(
_fullPath,
path);

// This will also ensure "path" is valid.
subDirPath = Path.GetFullPath(subDirPath);

return Directory.CreateDirectory(subDirPath);
}

/// <summary>
/// Returns a file list from the current directory.
/// </summary>
/// <returns>
/// An array of type <see cref="FileInfo"/>.
/// </returns>
/// <exception cref="IOException"> Logical drive or a directory under given path does not exist. </exception>
public FileInfo[] GetFiles()
{
string[] fileNames = Directory.GetFiles(_fullPath);

FileInfo[] files = new FileInfo[fileNames.Length];

for (int i = 0; i < fileNames.Length; i++)
{
files[i] = new FileInfo(fileNames[i]);
}

return files;
}

/// <summary>
/// Returns the subdirectories of the current directory.
/// </summary>
/// <returns>An array of <see cref="DirectoryInfo"/> objects.</returns>
public DirectoryInfo[] GetDirectories()
{
// searchPattern validation happening in the call
string[] dirNames = Directory.GetDirectories(_fullPath);

DirectoryInfo[] dirs = new DirectoryInfo[dirNames.Length];

for (int i = 0; i < dirNames.Length; i++)
{
dirs[i] = new DirectoryInfo(dirNames[i]);
}

return dirs;
}

/// <summary>
/// Moves a <see cref="DirectoryInfo"/> instance and its contents to a new path.
/// </summary>
/// <param name="destDirName">The name and path to which to move this directory. The destination cannot be another disk volume or a directory with the identical name. It can be an existing directory to which you want to add this directory as a subdirectory.</param>
/// <exception cref="IOException">An attempt was made to move a directory to a different volume. -or- <paramref name="destDirName"/> already exists. -or- The source directory does not exist. -or- The source or destination directory name is <see langword="null"/>.</exception>"
/// <exception cref="ArgumentNullException"><paramref name="destDirName"/> is <see langword="null"/>.</exception>"
public void MoveTo(string destDirName)
{
// destDirName validation happening in the call
Directory.Move(
_fullPath,
destDirName);
}

/// <inheritdoc/>
public override void Delete()
{
Directory.Delete(_fullPath);
}

/// <summary>
/// Deletes this instance of a <see cref="DirectoryInfo"/>, specifying whether to delete subdirectories and files.
/// </summary>
/// <param name="recursive"><see langword="true"/> to delete this directory, its subdirectories, and all files; otherwise, <see langword="false"/>.</param>
public void Delete(bool recursive)
{
Directory.Delete(
_fullPath,
recursive);
}

/// <summary>
/// Returns the original path that was passed to the <see cref="DirectoryInfo"/> constructor. Use the <see cref="FileSystemInfo.FullName"/> or <see cref="Name"/> properties for the full path or file/directory name instead of this method.
/// </summary>
/// <returns>The original path that was passed by the user.</returns>
public override string ToString()
{
return _fullPath;
}
}
}
Loading