113 Commits

Author SHA1 Message Date
Jeremy Schonfeld
7f9238e35a
[Windows] Implement additional file attributes (#730)
* Implement additional windows file attributes

* Ensure GetFileInformationByHandle succeeds

Co-authored-by: Saleem Abdulrasool <compnerd@compnerd.org>

* Correctly determine executability of file

* Simplify executable check

* Make .deviceIdentifier a future TODO

---------

Co-authored-by: Saleem Abdulrasool <compnerd@compnerd.org>
2024-07-12 13:38:57 -07:00
Saleem Abdulrasool
88d6a8d619
FoundationEssentials: make build on Android (#705)
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.
2024-07-01 16:44:47 -07:00
Saleem Abdulrasool
a7692238a8
FoundationEssentials: initial pass to add Android support (#704)
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.
2024-06-26 16:00:37 -07:00
Charles Hu
60506f3af4
Renamed _CShims to _FoundationCShims (#656)
Rationale: _CShims will effectivly become semi-public in the toolchain. We add the Foundation prefix to make it less generic.
2024-06-21 16:18:38 -07:00
Jeremy Schonfeld
7ee35fbeff
Add some WASI conditionals to FileManager (#681) 2024-06-17 13:56:14 -07:00
Charles Hu
8976fc4fd6
Introduce Cmake support for SwiftFoundation (#573) 2024-06-16 22:21:28 -07:00
Saleem Abdulrasool
142f409bcc
FoundationEssentials: relax error handling for SHGetFolderPath (#676)
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.
2024-06-12 13:19:27 -07:00
Saleem Abdulrasool
e473ab75be
FoundationEssentials: fix up linkOrCopyFile on Windows (#675)
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).
2024-06-12 09:26:03 -07:00
Saleem Abdulrasool
21ed596f06
FoundationEssentials: adjust error code thrown (#671)
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.
2024-06-12 08:37:16 -07:00
Saleem Abdulrasool
1d8050cf8e
FoundationEssentials: handle directory diff properly (#666)
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!
2024-06-06 16:42:26 -07:00
Saleem Abdulrasool
dd9910ba19
FoundationEssentials: ensure that the path exists before iteration (#665)
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.
2024-06-06 14:33:18 -07:00
Saleem Abdulrasool
9371cbf702
FoundationEssentials: correct callbacks for moveItem(atPath:toPath:) (#661)
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.
2024-06-06 13:54:46 -07:00
Saleem Abdulrasool
38d2d4e7a8
FoundationEssentials: silence a warning (#662)
Convert a `var` to `let` as it was originally. This variable is no
longer mutated and causes a warning.
2024-06-06 09:52:59 -07:00
Saleem Abdulrasool
413b15cbd8
FoundationEssentials: tweak removeFile(_:with:) on Windows (#659)
Ensure that we call the callbacks at the appropriate time. Change the
indentation and encapsulating scope to avoid a double callback.
2024-06-05 13:31:20 -07:00
Jeremy Schonfeld
418fe5bf96
Eliminate removefile shims fixing release mode build (#655)
* (128703942) Eliminate removefile shims

* state -> _
2024-06-04 20:03:35 -07:00
Saleem Abdulrasool
142c2378ea
FoundationEssentials: repair readlink implementation on Windows (#642)
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.
2024-06-04 11:42:50 -07:00
Tony Parker
caa08cf226
Enable complete concurrency checking in Foundation 2024-06-04 10:41:59 -07:00
Saleem Abdulrasool
2e26c64cc4
FoundationEssentials: correct the entry spelling for iteration (#653)
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.
2024-06-04 09:57:02 -07:00
Saleem Abdulrasool
f89df9d5f3
FoundationEssentials: ensure that the path exists when stat'ing (#647)
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.
2024-06-03 10:12:28 -07:00
Jeremy Schonfeld
14a64b0338
Prevent throwing when applying file attributes retrieved via attributesOfItem(atPath:) (#644)
* Ensure we don't throw when applying attributes retrieved via attributesOfItem(atPath:)

* Correct logic for FOUNDATION_FRAMEWORK
2024-06-03 09:23:15 -07:00
Jeremy Schonfeld
3297fb33b4
Return file attributes as NSNumbers when SCL-F is imported (#641) 2024-05-29 14:06:38 -07:00
Saleem Abdulrasool
6061198cb9
FoundationEssentials: limit autosave to user domain (#637)
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.
2024-05-28 09:10:35 -07:00
Saleem Abdulrasool
2c35194783
FoundationEssentials: provide a known directory for "Autosave Information" (#636)
This adds a missing expected case for a known URL for storage.
2024-05-28 08:31:38 -07:00
Saleem Abdulrasool
02e110faf6
FoundationEssentials: add type to the file attributes on Windows (#634)
Get the file type using the Win32 APIs and wire that into the attribute
dictionary.
2024-05-28 05:04:37 -07:00
Saleem Abdulrasool
d73d7c1370
FoundationEssentials: account for relative paths in iteration (#635)
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.
2024-05-24 09:56:28 -07:00
Saleem Abdulrasool
f657181b05
FoundationEssentials: correct directory enumeration on Windows (#629)
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.
2024-05-22 11:17:09 -07:00
Saleem Abdulrasool
4c26af5c20
FoundationEssentials: drop invalid modification dates (#628)
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.
2024-05-21 15:46:33 -07:00
Jeremy Schonfeld
b2f4b02cd4
(127489390) FileManager copyItem can throw different error codes compared to old ObjC implementation (#624) 2024-05-20 15:01:03 -07:00
Jeremy Schonfeld
64e4646a1b
Gracefully handle cases where the isDirectory url resource might not be set (#616)
Co-authored-by: Pierre Schweitzer <pschweitzer@apple.com>
2024-05-16 15:57:43 -07:00
Saleem Abdulrasool
e2f85ccd61
FoundationEssentials: avoid precondition failure on Windows (#611)
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.
2024-05-15 13:48:53 -07:00
Jeremy Schonfeld
db63ab39bb
(128078561) Fix FileManager bugs found by scl-f (#609) 2024-05-15 11:03:07 -07:00
Saleem Abdulrasool
d1ace948b5
(128078378) FoundationEssentials: correct error handling for item removal (#610)
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.
2024-05-14 13:40:54 -07:00
Saleem Abdulrasool
d91433d415
(128068690) FoundationEssentials: repair the Windows build (#608)
Repair the Windows build after recent additions for FileManager.
2024-05-14 11:37:08 -07:00
Jeremy Schonfeld
cae149702b
Add non-darwin search paths (#598)
* Add non-darwin search paths

* Address review feedback

* Resolve build failures

* Resolve more build failures

* Fix test failures
2024-05-10 15:17:19 -07:00
Jeremy Schonfeld
727bd07830
Utilize URL in FileManager (#589)
* Use URL in FileManager

* Fix warnings

* Fix build failures on Linux

* Remove Locale_ICU warning fix
2024-05-07 15:55:08 -07:00
Jonathan Flat
361efcf5fe
Port URL and URLComponents to swift-foundation (#586) 2024-05-06 09:51:18 -07:00
Saleem Abdulrasool
6c151ca765
FoundationEssentials: implement file diffing support for Windows (#548)
* 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.
2024-04-30 10:38:31 -07:00
Saleem Abdulrasool
6ff08b28b8
FoundationEssentials: repair the Windows build after tweaks (#570)
The changes to repair the macOS/Linux build adversely impacted the
Windows build. Accommodate the API and logic changes for Windows.
2024-04-30 08:00:13 -07:00
Saleem Abdulrasool
aabac27b21
FoundationEssentials: implement file operations (#566)
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.
2024-04-29 15:34:46 -07:00
Saleem Abdulrasool
c5e734c89a
FoundationEssentials: enable unprivilleged symlinks if possible (#556)
If developer mode is enabled or the user is assigned the
SeCreateSymbolicLinkPrivilege privilege, permit the unelevated symbolic
link creation.
2024-04-26 10:11:51 -07:00
Jeremy Schonfeld
67ebbb9faa
(126758003) FileManager doesn't defer to subclasses when creating symbolic links 2024-04-25 16:38:45 -07:00
Saleem Abdulrasool
d80478289c
(127077121) FoundationEssentials: support directory enumeration operations on Windows (#554)
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.
2024-04-25 16:11:30 -07:00
Saleem Abdulrasool
e75fbb330a
(126693736) FoundationEssentials: support changing directories on Windows
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.
2024-04-18 10:47:51 -07:00
Saleem Abdulrasool
d7bad7ce73
FoundationEssentials: support symbolic link operations on Windows
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.
2024-04-12 11:40:18 -07:00
Saleem Abdulrasool
b80fb683b6
FoundationEssentials: provide typed overloads for constants from WinSDK
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.
2024-04-11 15:53:31 -07:00
Saleem Abdulrasool
b2ba6f6f1c
FoundationEssentials: tweak FileManager utilities for Windows (#537)
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.
2024-04-10 16:37:03 -07:00
Saleem Abdulrasool
dbde80012d
(126089580) FoundationEssentials: repair FileManager.currentDirectoryPath on Win32
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.
2024-04-08 17:20:23 -07:00
Saleem Abdulrasool
700fb4324d
FoundationEssentials: squelch some warnings (#525)
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.
2024-04-03 13:14:12 -07:00
Saleem Abdulrasool
9491cce69c
FoundationEssentials: add some missing imports for Windows (#520)
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.
2024-03-29 14:19:23 -07:00
Jeremy Schonfeld
c9b00fa160
(123972921) _SearchPaths doesn't correctly mask invalid domains 2024-03-25 11:21:13 -07:00