Skip to content

Rewrite your app in Rust, piece by piece, checked against the original at every step. Works with TypeScript, JavaScript, Python, Go, Ruby, Java, C, PHP, C#, Kotlin, PowerShell and Swift.

Swift: count FileManager.default.temporaryDirectory, NSUserName and NSFullUserName as environment reads (#1457) (#1491)

Hashem Alkhanaizi41ee48228e9c
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 21c5a6ab..51dcbe71 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -29,6 +29,10 @@
- Go: `os.Getpid()`, `os.Getppid()`, `os.Getuid()` and `os.Getgid()` count as reading the
environment, and `time.Until()` as reading the clock, the mirror of `time.Since()`, so `bridge`
keeps a function that calls one in Go and `analyze` counts it (#1455).
+- Swift: `FileManager.default.temporaryDirectory`, `NSUserName()` and `NSFullUserName()` count as
+ reading the environment, as `NSTemporaryDirectory()` and `NSHomeDirectory()` do, so `bridge` keeps
+ a function that calls one in Swift and `analyze` lists it under "State outside the arguments"
+ (#1457).
- npm: `rust-anything` no longer bundles the binaries of all five platforms (210 MB unpacked). Each
platform's binary is its own package (`rust-anything-darwin-arm64`, `-darwin-x64`, `-linux-arm64`,
`-linux-x64`, `-win32-x64`), listed as an optional dependency, so `npm install` and `npx` fetch only
diff --git a/src/lang/effects.rs b/src/lang/effects.rs
index 2a093136..193af427 100644
--- a/src/lang/effects.rs
+++ b/src/lang/effects.rs
@@ -238,8 +238,11 @@ fn environment(lang: Lang) -> &'static [&'static str] {
"FileManager.default.currentDirectoryPath",
// In full: a name after `.` is skipped, so `homeDirectoryForCurrentUser` alone never matches.
"FileManager.default.homeDirectoryForCurrentUser",
+ "FileManager.default.temporaryDirectory",
"NSHomeDirectory(",
"NSTemporaryDirectory(",
+ "NSUserName(",
+ "NSFullUserName(",
"getenv(",
],
Lang::C => &[
@@ -1765,6 +1768,18 @@ mod tests {
"function f($x) { return sys_get_temp_dir() . $x; }",
),
(Lang::Php, "function f($x) { return getmypid() . $x; }"),
+ (
+ Lang::Swift,
+ "public func f(_ x: String) -> String {\n return FileManager.default.temporaryDirectory.path + x\n}",
+ ),
+ (
+ Lang::Swift,
+ "public func f(_ x: String) -> String {\n return NSUserName() + x\n}",
+ ),
+ (
+ Lang::Swift,
+ "public func f(_ x: String) -> String {\n return NSFullUserName() + x\n}",
+ ),
(Lang::Powershell, "function F { param($X) $env:HOME + $X }"),
(
Lang::C,