42 Commits

Author SHA1 Message Date
Jake Petroules
c16e0d9a48
Fix FileManager.isExecutableFile for emulated x86 processes on ARM systems (#1246)
GetBinaryType will return ERROR_BAD_EXE_FORMAT when querying an arm64 executable from an x86 process running on an ARM system. This change switches the implementation to use SHGetFileInfoW, which isn't subject to this quirk.

This also makes isExecutableFile behave more similarly to other platforms -- e.g. isExecutableFile already returns true for any file with the execute bit, even for an arm64 executable on an x86_64 macOS system (which it can't actually run). The spirit of the API is that the file is of an executable type, not necessarily that the running system is capable of executing it.

The practical consequence of fixing this bug is that queries like:

```swift
FileManager.default.isExecutableFile(atPath: "C:\\Windows\\system32\\cmd.exe")
```

will now correctly return true regardless of what architecture the binary is compiled for or what type of system it's running on.

Closes #860
2025-04-11 09:12:53 -07:00
3405691582
03fe46f43b
OpenBSD support. (#1126)
* Advise porter on where to make necessary change.

In #1075 the change was already made for BSD (thank you!); my working
edit had this guidance to ensure future porters get an error directing
them where to make a necessary change.

Otherwise, the FoundationEssentials build will fail and complain these
variables are not defined but not have guidance as to where they are
sourced from.

* OpenBSD does not support extended attributes.

* OpenBSD does not have secure_getenv.

* Remaining OpenBSD changes.

* OpenBSD also needs `pthread_mutex_t?`.

* Originally I followed Darwin's check with `d_namlen`, but this should
  work too.

* Correct statvfs type casts for OpenBSD.

On OpenBSD, fsblkcnt_t -- the type of f_blocks -- is a UInt64; therefore,
so must `blockSize` be.

Ultimately, both sides of the `totalSizeBytes` multiplication should
probably be type cast for all platforms, but that's a more significant
functional change for another time.

* Default activeProcessorCount to 1, not 0.

After a rather tedious debugging session trying to figure out why
swiftpm-bootstrap appeared to be deadlocked, this turned out to be the
culprit. Perhaps this should be #error instead, but for now, set a
sensible default.

* Use sysconf for activeProcessorCount.

This is what Dispatch does in some places for OpenBSD anyway, so do
likewise here.
2025-04-07 10:46:18 -07:00
Kenta Kubo
68dd6d85a6
[wasm] Make FileManager.createFile() work on WASI (#992)
* [wasm] Make `FileManager.createFile()` work on WASI

fixes swiftwasm/swift#5593

`FileManager.createFile()` currently doesn't work on WASI because it
requires `.atomic`, it requires creating a temporary file, and it isn't
suppported on WASI.

So I have fixed that by removing the `.atomic` requirement only on WASI.

* [wasm] Make `Data.WritingOptions.atomic` unavailable on WASI

`writeToFileAux`, `createTemporaryFile`, and `createProtectedTemporaryFile` also become unavailable on WASI.
2025-03-25 09:42:15 -07:00
Christopher Thielen
fa43c96f5f
Move temporarily relocated FileManager extensions back to their original locations (#1213) 2025-03-18 11:29:53 -07:00
Johannes Weiss
601e847faa
always @preconcurrency import Glibc (#1175)
Co-authored-by: Johannes Weiss <johannes@jweiss.io>
2025-03-04 09:25:51 -08:00
Jeremy Schonfeld
c55993dd5b
Prevent crashing when calling quotactl with UIDs greater than Int32.max (#1146)
* Prevent crashing when calling quotactl with UIDs greater than Int32.max

* Add comment
2025-01-29 09:13:39 -08:00
Christopher Thielen
215f1ce06b
Publish NSString bridging (#1133)
* Publish NSString->String bridging

* Relocate Swift extensions of some Objective-C NS_TYPED_ENUM types to work around swiftlang/swift #78731
2025-01-22 13:29:41 -08:00
michael-yuji
5ed6c72484
[FreeBSD] Fix FreeBSD build/support (#1075)
* FreeBSD platform specific fixes

- Use "/usr/share/zoneinfo"
- Use platform specific types and values
- Implement extattr ops for FreeBSD
- Use copy_file_range(2) for file cloning

* Revise patch to ProcessInfo to reduce potential impact to other platforms

* Fix macOS build

* typo

* take suggested change
2025-01-10 14:20:27 -08:00
Jeremy Schonfeld
71eefee7fc
Fetching user/group info causes race conditions (#994)
* Avoid racy stdlib functions for fetching user/group info

* Refactor naming

* Fix build failure
2024-10-23 09:18:15 -07:00
finagolfin
53ffff0600
[Android] Enable more code and tests (#871)
* [Android] Enable more code and tests

while disabling setting extended file attributes and a test creating a hard link,
features not normally allowed on Android.

* Remove incorrect WASI check
2024-09-17 08:40:40 -07:00
Jeremy Schonfeld
7242610c89
FileManager.fileExists(atPath:) should follow symlinks (#859) 2024-08-16 11:19:26 -07:00
finagolfin
c15a5e1f5c
[Android] Use the Bionic module in more places (#842)
Also, use `canImport()` wherever importing APIs, reserving `os(Android)` for
platform differences.
2024-08-15 14:34:15 -07:00
Evan Wilde
aecc1b158c
[main] Get Swift-Foundation building against MUSL for Swift Static SDK (#848)
* Get FoundationEssentials building

Adding the missing musl imports to get FoundationEssentials building for
the Swift static SDKs again.

Also providing an option to disable building the macros. The macros
aren't necessary for building the library and will not be run as part of
the static SDK. No need to bloat the SDK or build times further. For
Swift 6, the macros should be provided by the toolchain since the
toolchain and SDK are current revlocked due to swiftmodules.

* Get FoundationInternationalization building

Adding the missing Musl imports to get FoundationInternationalization
building for the static SDK.
2024-08-14 13:34:15 -07:00
Alex Lorenz
ad6ca71b4e
[android] fix the LP32 armv7/i686 android build (#846)
* [android] fix the LP32 armv7/i686 android build

* Update Sources/FoundationEssentials/Android+Extensions.swift

Co-authored-by: Jeremy Schonfeld <1004103+jmschonfeld@users.noreply.github.com>

* drop the android Lp32 specific operator &

---------

Co-authored-by: Jeremy Schonfeld <1004103+jmschonfeld@users.noreply.github.com>
2024-08-14 10:56:25 -07:00
Jeremy Schonfeld
a57b06e39f
Remove _typeByName lookup of _FoundationNSNumberInitializer (#817) 2024-08-02 13:56:03 -07:00
Yuta Saito
c82d1673eb
Add WASI platform conditions for libc imports and word size (#776)
* Add `import WASILibc` statements to libc import chains

* Declare wasm32 arch as 32-bit environment

* Switch to _pointerBitWidth for architecture checks

This change switches the architecture checks in Data.swift to use the
_pointerBitWidth instead of the arch() checks for consistency with newer
platforms.
2024-08-02 09:55:56 -07:00
Yuta Saito
e90b6c3f90
Skip sticky-bit check in isDeletableFile on WASI (#785)
WASI does not surface the sticky bit and getuid, so we cannot check
whether the file is actually deletable before attempting to delete it.
2024-08-01 09:30:17 -07:00
Yuta Saito
0b3974d351
Guard out user/group related code on WASI (#783)
* Guard out user/group related code on WASI

This change guards out the user/group related code on WASI, as WASI does
not have the concept of users or groups.

* Throw explicit unsupported error if trying to set user or group on WASI

Instead of implicitly ignoring user-given values, we should throw
exception to make it clear that those values cannot be set on WASI.
2024-08-01 09:23:13 -07:00
Yuta Saito
fab7195ea2
Guard out extended or fs attributes related code on WASI (#784)
This commit guards out the extended attributes and file system
attributes related code on WASI as WASI does not support these
features. Just return nothing or ignore the set request.
2024-08-01 09:20:05 -07:00
Jeremy Schonfeld
b4c77a35f9
Correctly set .fileTypeSymlink on windows (#773) 2024-07-26 13:14:19 -07:00
Jeremy Schonfeld
008613336a
Enable reading attributes of directory on Windows (#770) 2024-07-25 16:11:48 -07:00
Jeremy Schonfeld
196376b5fd
Use dynamic replacement instead of _typeByName for internationalization upcalls (#756)
* Use dynamic replacement instead of _typeByName for internationalization upcalls

* Make FOUNDATION_FRAMEWORK function non-dynamic

* Fix build failures
2024-07-23 14:43:01 -07:00
Jeremy Schonfeld
b58b05100c
Fully enable posixPermissions attribute on Windows (#733) 2024-07-15 12:25:35 -07:00
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
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
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
3297fb33b4
Return file attributes as NSNumbers when SCL-F is imported (#641) 2024-05-29 14:06: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
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
db63ab39bb
(128078561) Fix FileManager bugs found by scl-f (#609) 2024-05-15 11:03:07 -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
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
c1e5321e8d
(125120887) attributesForItem(atPath:) uses FileAttributeType instead of String for .type value 2024-03-21 15:51:16 -07:00
Jeremy Schonfeld
e9a621c6ef
(124077456) FileManager should not crash on malformed modificationDate attribute value 2024-03-13 10:44:59 -07:00
Jeremy Schonfeld
75f2ae99e4
(123713046) FileManager should always return values for immutable/appendOnly attributes
* (123713046) Ensure we always return values for immutable/appendOnly file attributes

* (123713046) Disable test on non-Darwin
2024-03-08 11:25:52 -08:00
Jeremy Schonfeld
e5211f2926
(122981400) Standardize on using internal import 2024-03-06 13:42:02 -08:00
Jeremy Schonfeld
f28d05ad9d
(122854809) Fix error handling for reading extended attributes 2024-02-13 18:55:36 -08:00
Jeremy Schonfeld
f99560eea6
(122800483) Add missing FOUNDATION_FRAMEWORK import for file protection classes 2024-02-12 10:37:52 -08:00
Jeremy Schonfeld
33856a556d
(120741818) Port FileManager to swift-foundation
* (120741818) Port FileManager to swift-foundation

* (120741818) Fix linux test failures

* (120741818) Fix build failures
2024-02-09 15:03:43 -08:00