Repository navigation
Commit 00bd762
authored
[flutter_tools] Safely handle broken symlinks and existing files during plugin symlink creation (#191496)
## Description
Fixes a crash during plugin symlink creation on Windows/Linux desktop
builds (`FileSystemException: Creation failed, OS Error: A file cannot
be created if it already exists., errno = 183` / `errno = 17`).
### Cause
Previously, `_createPlatformPluginSymlinks` checked `if
(link.existsSync()) continue;` before calling `link.createSync(path)`.
1. If a non-link entity (such as a regular directory or file from manual
extraction, git checkout, or previous builds) occupied the symlink path,
`Link.existsSync()` returned `false`. The tool then called
`link.createSync(path)`, crashing with `ERROR_ALREADY_EXISTS` (`errno =
183`) on Windows or `EEXIST` (`errno = 17`) on POSIX.
2. `Link.existsSync()` did not check if an existing symlink pointed to
the expected plugin target path. If a plugin's path changed (e.g. a
version upgrade in pub cache), existing symlinks pointing to outdated
paths were skipped.
### Fix
- Uses `typeSync(link.path, followLinks: false)` to inspect disk state
type-agnostically before symlink creation.
- Canonicalizes and compares `link.targetSync()` with `path`. If
matching, creation is skipped.
- Deletes stale or mismatched links via
`ErrorHandlingFileSystem.deleteIfExists(link)`, and removes conflicting
non-link entries before calling `link.createSync(path)`.
## Related Issues
* Fixes #90028
* Related to #131978
* Related to #74227
## Tests
- `packages/flutter_tools/test/general.shard/plugins_test.dart`:
- `createPluginSymlinks repairs broken symlinks without failing`
- `createPluginSymlinks replaces existing files with symlinks without
failing`1 parent 1d790af commit 00bd762
2 files changed
Lines changed: 85 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1248 | 1248 | | |
1249 | 1249 | | |
1250 | 1250 | | |
1251 | | - | |
1252 | | - | |
| 1251 | + | |
| 1252 | + | |
| 1253 | + | |
| 1254 | + | |
| 1255 | + | |
| 1256 | + | |
| 1257 | + | |
| 1258 | + | |
| 1259 | + | |
| 1260 | + | |
| 1261 | + | |
| 1262 | + | |
| 1263 | + | |
| 1264 | + | |
| 1265 | + | |
| 1266 | + | |
| 1267 | + | |
| 1268 | + | |
| 1269 | + | |
| 1270 | + | |
1253 | 1271 | | |
1254 | 1272 | | |
1255 | 1273 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2009 | 2009 | | |
2010 | 2010 | | |
2011 | 2011 | | |
| 2012 | + | |
| 2013 | + | |
| 2014 | + | |
| 2015 | + | |
| 2016 | + | |
| 2017 | + | |
| 2018 | + | |
| 2019 | + | |
| 2020 | + | |
| 2021 | + | |
| 2022 | + | |
| 2023 | + | |
| 2024 | + | |
| 2025 | + | |
| 2026 | + | |
| 2027 | + | |
| 2028 | + | |
| 2029 | + | |
| 2030 | + | |
| 2031 | + | |
| 2032 | + | |
| 2033 | + | |
| 2034 | + | |
| 2035 | + | |
| 2036 | + | |
| 2037 | + | |
| 2038 | + | |
| 2039 | + | |
| 2040 | + | |
| 2041 | + | |
| 2042 | + | |
| 2043 | + | |
| 2044 | + | |
| 2045 | + | |
| 2046 | + | |
| 2047 | + | |
| 2048 | + | |
| 2049 | + | |
| 2050 | + | |
| 2051 | + | |
| 2052 | + | |
| 2053 | + | |
| 2054 | + | |
| 2055 | + | |
| 2056 | + | |
| 2057 | + | |
| 2058 | + | |
| 2059 | + | |
| 2060 | + | |
| 2061 | + | |
| 2062 | + | |
| 2063 | + | |
| 2064 | + | |
| 2065 | + | |
| 2066 | + | |
| 2067 | + | |
| 2068 | + | |
| 2069 | + | |
| 2070 | + | |
| 2071 | + | |
| 2072 | + | |
| 2073 | + | |
| 2074 | + | |
| 2075 | + | |
| 2076 | + | |
2012 | 2077 | | |
2013 | 2078 | | |
2014 | 2079 | | |
| |||
0 commit comments