This adjusts the API usage to account for differences on Android. The
biggest source of difference is the nullability, particularly in the
`fts` APIs. Unfortunately, `MMAP_FAILED` is not imported by the clang
importer due to the casting involved so we manually inline the constant
at the single site.
This adds the necessary guards and includes for the Android modules.
While the module does not compile currently due to nullability
differences (and in some cases missing declarations), this at least
brings the module to a point where we can start working on the errors
and differences to create a maintainable codebase for Android.
When running in CI, we would see failures due to the environment
variables being changed. This relaxes the precondition to allow the test
failure to propagate.
Adjust the Windows path for copying (or linking) files. This adds the
missing recursion in the copy (the documentation for `CopyFile2` was not
clear that the recursive copy is not performed).
Rather than relaying the underlying system error, replace the error with
the expected error code. This repairs the test case expectation of the
thrown error.
We need to use `FILE_FLAG_BACKUP_SEMANTICS` to ensure that we are able
to diff directories as well. Previously we would mishandle this case and
was caught by the test suite.
Thanks to Jeremy Day for helping resolve this!
When performing a `subpathsOfDirectory`, ensure that the path exists. On
the non-Windows path, `_FTSSequence` will perform the initial `statvfs`
during construction which obscured this requirement. We instead
explicitly inline this call in the implementation. This repairs further
test failures.
In the case that the destination exists, we should check for continue
after error. If the source does not exist, simply do nothing.
Furthermore, adjust the test to ensure that we are using the path
spelling rather than the FSR.
Take the opportunity to correct an error in the tests where we would not
check the correct captured item set.
The existing code did not properly read the structure (possibly due to
copying). This adjustst he path to use `UnsafePointer` to use that to
read the data from the response of the `ioctl` call.
When running the test suite we would hit an infinite loop due to the use
of the relative path rather than the absolute path for accessing the
attributes of the file entry.
On non-Windows targets we ensure that the path exists when we attempt to
query the attributes of the path. This adds the same check on Windows so
that we can have similar behaviour on all platforms.
During the review for the changes to support Windows, we realized that
the location that is being used for the autosave information is only
available within the user domain mask. The Windows implementation was
corrected as part of the implementation, but this corrects the XDG
compliant path to reflect this reality.
We are not changing the working directory in between recursive calls.
This is a problem when trying to enumerate the subpaths of a directory
in the recursive call where the parent path was lost. Concatenate the
parent path before recursing.
When enumerating a directory on Windows, we would fail to increment the
iterator as we would increment _after_ the return. Insert a `defer`'ed
increment on the iterator to allow us to track the state properly.
Because the iteration was may have completed on the previous run, we
need to track an additional bit of state as `bValid` which provides us
an indication if iteration has completed.
Follow the expected behaviour to drop invalid modification dates, e.g.
`+NaN`. This matches the semantics that are expected on Unix and avoids
a crash due to the initialiser.
Repair the error reporting on Windows in the case of a failure in
`SHGetKnownFolder` - the returned value is a `HRESULT`, which is the
extended error code unlike the Win32 APIs which return a `BOOL`.
The "Recyle Bin" is a virtual folder and does not have an associated
path with the folder that we can query. Undo the implementation here for
the time being to avoid the assertion failure in the runtime.
The condition of the error check was inverted as it was meant to be a
`guard` statement. This was resulting in an infinite loop. With this we
now pass a few additional tests and the test suite no longer hangs.
* FoundationEssentials: repair the Windows build after tweaks
The changes to repair the macOS/Linux build adversely impacted the
Windows build. Accommodate the API and logic changes for Windows.
* FoundationEssentials: implement file diffing support for Windows
Windows does not have the same Unix file system APIs (e.g. FTS).
Implement a platform specific implementation to compare files on
Windows.
This adds an initial implementation for file operations on Windows. With
this, `FileManager` should at least build on Windows, which unblocks
future work as well as brings us closer to enabling
`FoundationEssentials` on Windows.
Implement the directory enumeration operations in FileManager on
Windows. The implementation uses the Win32 API surface to ensure that we
can use the full features of the platform.
We should be using the NT Path representation to ensure that we can use
long paths. Additionally, we need to use the UTF16 encoded variant of
the path rather than the UTF-8. Adjust the changing directory path to
account for this.
This adjusts the symbolic link paths to be supported on Windows. The
symbolic link destination computation is particularly gnarly as it
requires re-defining the device driver interface in a shim header to
access that and then performing aliasing contortions to gain access to
the trailing VLA to get the value.
This allows for us to use the constants without explicitly casting the
type to `DWORD` on each site of use. By providing the shadowing
overload we can simply use the constants without impacting the
readability of the surrounding code.
Add a helper for time conversion and remove some functions which do not
make sense on Windows - users are not identified by integral IDs but
rather by SIDs. This helps reduce the error diagnostics when building
FoundationEssentials on Windows.
Use the Windows APIs properly to compute the current working directory.
Query the required storage before performing the allocation and then use
temporary storage to acquire a buffer. This repairs some of the build
errors encountered when building on Windows.
When trying to revive the Windows port, these warnings clutter the
current set of things to resolve still. Silence the warnings by
explicitly ignoring the results.
This allows us to get further into building FoundationEssentials once
again on Windows. Much of the file system work has resulted in this
module no longer being viable on Windows and will need to be replaced to
allow building on Windows which does not have the `fts` APIs.