You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As described in the RFC, the differences in how creating symlinks works
differs sufficiently between Unix and Windows that trying to have a
cross-platform API is a compability hazard.
If you do a Google search for "[windows symbolic link](https://www.google.com/search?q=windows+symbolic+link&ie=utf-8&oe=utf-8)" or "[windows soft link](https://www.google.com/search?q=windows+soft+link&ie=utf-8&oe=utf-8)",
57
93
many of the documents you find start using "symlink" after introducing the
@@ -60,9 +96,14 @@ among Windows developers and users.
60
96
61
97
# Detailed design
62
98
63
-
Rename `std::fs::soft_link` to `std::fs::symlink`, and provide a deprecated
64
-
`std::fs::soft_link` wrapper for backwards compatibility. Update the
65
-
documentaiton to use "symbolic link" in prose, rather than "soft link".
99
+
Move `std::fs::soft_link` to `std::os::unix::fs::symlink`, and create
100
+
`std::os::windows::fs::symlink_file` and `std::os::windows::fs::symlink_dir`
101
+
that call `CreateSymbolicLink` with the appropriate arguments.
102
+
103
+
Keep a deprecated compatibility wrapper `std::fs::soft_link` which wraps
104
+
`std::os::unix::fs::symlink` or `std::os::windows::fs::symlink_file`,
105
+
depending on the platform (as that is the current behavior of
106
+
`std::fs::softlink`, to create a file symbolic link).
66
107
67
108
# Drawbacks
68
109
@@ -71,7 +112,27 @@ around.
71
112
72
113
# Alternatives
73
114
74
-
Other choices for the name would be:
115
+
* Have a cross platform `symlink` and `symlink_dir`, that do the same thing on
116
+
Unix but differ on Windows. This has the drawback of invisible
117
+
compatibility hazards; code that works on Unix using `symlink` may fail
118
+
silently on Windows, as creating the wrong type of symlink may succeed but
119
+
it may not be interpreted properly once a destination file of the other type
120
+
is created.
121
+
* Have a cross platform `symlink` that detects the type of the destination
122
+
on Windows. This is not always possible as it's valid to create dangling
123
+
symbolic links.
124
+
* Have `symlink`, `symlink_dir`, and `symlink_file` all cross-platform, where
125
+
the first dispatches based on the destination file type, and the latter two
126
+
panic if called with the wrong destination file type. Again, this is not
127
+
always possible as it's valid to create dangling symbolic links.
128
+
* Rather than having two separate functions on Windows, you could have a
129
+
separate parameter on Windows to specify the type of link to create;
130
+
`symlink("a", "b", FILE_SYMLINK)` vs `symlink("a", "b", DIR_SYMLINK)`.
131
+
However, having a `symlink` that had different arity on Unix and Windows
132
+
would likely be confusing, and since there are only the two possible
133
+
choices, simply having two functions seems like a much simpler solution.
134
+
135
+
Other choices for the naming convention would be:
75
136
76
137
* The status quo, `soft_link`
77
138
* The original proposal from rust-lang/rfcs#517, `sym_link`
@@ -83,12 +144,29 @@ Unix. It is a classic compromise, that makes everyone unhappy.
83
144
`sym_link` is slightly more consistent with the complementary `hard_link`
84
145
function, and treating "sym link" as two separate words has some precedent in
85
146
two of the Windows-targetted APIs, Delphi and some of the PowerShell cmdlets
86
-
observed.
147
+
observed. However, I have not found any other snake case API that uses that,
148
+
and only a couple of Windows-specific APIs that use it in camel case; most
149
+
usage prefers the single word "symlink" to the two word "sym link" as the
150
+
abbreviation.
87
151
88
152
The full name `symbolic_link`, is a bit long and cumbersome compared to most
89
153
of the rest of the API, but is explicit and is the term used in prose to
90
154
describe the concept everywhere, so shouldn't emphasize any one platform over
91
-
the other.
155
+
the other. However, unlike all other operations for creating a file or
156
+
directory (`open`, `create`, `create_dir`, etc), it is a noun, not a verb.
157
+
When used as a verb, it would be called "symbolically link", but that sounds
158
+
quite odd in the context of an API: `symbolically_link("a", "b")`. "symlink",
159
+
on the other hand, can act as either a noun or a verb.
160
+
161
+
It would be possible to prefix any of the forms above that read as a noun with
162
+
`create_`, such as `create_symlink`, `create_sym_link`,
163
+
`create_symbolic_link`. This adds further to the verbosity, though it is
164
+
consisted with `create_dir`; you would probably need to also rename
165
+
`hard_link` to `create_hard_link` for consistency, and this seems like a lot
166
+
of churn and extra verbosity for not much benefit, as `symlink` and
167
+
`hard_link` already act as verbs on their own. If you picked this, then the
168
+
Windows versions would need to be named `create_file_symlink` and
169
+
`create_dir_symlink` (or the variations with `sym_link` or `symbolic_link`).
0 commit comments