Commit 92c3b69
Libor
feat: allow
This PR introduces a new argument to `System.FilePath.walkDir` - `followLinks` - which allows
the callee to not follow symbolic links and is set to `false` as default.
Rationale:
`System.FilePath.metadata` action follows symlinks, therefore
the branch `| ok { type := .symlink, .. }` was in fact unreachable. We
can leverage the `symlinkMetadata` action introduced in add3e1a
which uses the `lstat(2)` system call and does not follow symlinks.
This gives us the option to not follow symlinks and expose ourselves to
an infinite recursion when traversing a directory structure containing a
cycle - a situation that is currently unavoidable.
---
Rationale for setting the `followLinks := false` default:
I realize that setting the default as `false` is a breaking change, and
I don't know the internal usage of `walkDir` well enough to see if it
breaks anything - from grepping and glancing at the code, not following
symlinks seems OK.
I consulted implementations of `walkDir` in other languages and
* Python stdlib `os.walk` - https://docs.python.org/3/library/os.html#os.walk
does not follow links by default
* Rust crate `walkdir` - https://docs.rs/walkdir/latest/walkdir/struct.WalkDir.html#method.follow_links
does not follow links by default
* Go stdlib `filepath/WalkDir` - https://pkg.go.dev/path/filepath#WalkDir
does not follow links at all.System.FilePath.walkDir to not follow symlinks1 parent 77ddfd4 commit 92c3b69
File tree
3 files changed
+69
-9
lines changed- src
- Init/System
- runtime
- tests/lean/run
3 files changed
+69
-9
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1143 | 1143 | | |
1144 | 1144 | | |
1145 | 1145 | | |
1146 | | - | |
| 1146 | + | |
| 1147 | + | |
1147 | 1148 | | |
1148 | 1149 | | |
1149 | | - | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
| 1153 | + | |
| 1154 | + | |
1150 | 1155 | | |
1151 | | - | |
| 1156 | + | |
1152 | 1157 | | |
1153 | 1158 | | |
1154 | 1159 | | |
1155 | 1160 | | |
1156 | 1161 | | |
1157 | 1162 | | |
1158 | 1163 | | |
1159 | | - | |
| 1164 | + | |
1160 | 1165 | | |
1161 | | - | |
1162 | | - | |
1163 | | - | |
1164 | | - | |
| 1166 | + | |
| 1167 | + | |
| 1168 | + | |
1165 | 1169 | | |
1166 | 1170 | | |
1167 | 1171 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1130 | 1130 | | |
1131 | 1131 | | |
1132 | 1132 | | |
1133 | | - | |
| 1133 | + | |
1134 | 1134 | | |
1135 | 1135 | | |
1136 | 1136 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
16 | 24 | | |
17 | 25 | | |
18 | 26 | | |
| |||
171 | 179 | | |
172 | 180 | | |
173 | 181 | | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
0 commit comments