forked from rust-lang/rustup
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.rs
More file actions
388 lines (378 loc) · 13.7 KB
/
Copy patherrors.rs
File metadata and controls
388 lines (378 loc) · 13.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
#![allow(clippy::large_enum_variant)]
use crate::component_for_bin;
use crate::dist::manifest::{Component, Manifest};
use crate::dist::temp;
use error_chain::error_chain;
use std::ffi::OsString;
use std::io::{self, Write};
use std::path::PathBuf;
use url::Url;
pub const TOOLSTATE_MSG: &str =
"If you require these components, please install and use the latest successful build version,\n\
which you can find at <https://rust-lang.github.io/rustup-components-history>.\n\nAfter determining \
the correct date, install it with a command such as:\n\n \
rustup toolchain install nightly-2018-12-27\n\n\
Then you can use the toolchain with commands such as:\n\n \
cargo +nightly-2018-12-27 build";
error_chain! {
links {
Download(download::Error, download::ErrorKind);
}
foreign_links {
Temp(temp::Error);
Io(io::Error);
Open(opener::OpenError);
Thread(std::sync::mpsc::RecvError);
}
errors {
LocatingWorkingDir {
description("could not locate working directory")
}
ReadingFile {
name: &'static str,
path: PathBuf,
} {
description("could not read file")
display("could not read {} file: '{}'", name, path.display())
}
ReadingDirectory {
name: &'static str,
path: PathBuf,
} {
description("could not read directory")
display("could not read {} directory: '{}'", name, path.display())
}
WritingFile {
name: &'static str,
path: PathBuf,
} {
description("could not write file")
display("could not write {} file: '{}'", name, path.display())
}
CreatingDirectory {
name: &'static str,
path: PathBuf,
} {
description("could not create directory")
display("could not create {} directory: '{}'", name, path.display())
}
ExpectedType(t: &'static str, n: String) {
description("expected type")
display("expected type: '{}' for '{}'", t, n)
}
FilteringFile {
name: &'static str,
src: PathBuf,
dest: PathBuf,
} {
description("could not copy file")
display("could not copy {} file from '{}' to '{}'", name, src.display(), dest.display())
}
RenamingFile {
name: &'static str,
src: PathBuf,
dest: PathBuf,
} {
description("could not rename file")
display("could not rename {} file from '{}' to '{}'",
name, src.display(), dest.display())
}
RenamingDirectory {
name: &'static str,
src: PathBuf,
dest: PathBuf,
} {
description("could not rename directory")
display("could not rename {} directory from '{}' to '{}'", name, src.display(), dest.display())
}
DownloadingFile {
url: Url,
path: PathBuf,
} {
description("could not download file")
display("could not download file from '{}' to '{}'", url, path.display())
}
DownloadNotExists {
url: Url,
path: PathBuf,
} {
description("could not download file")
display("could not download file from '{}' to '{}'", url, path.display())
}
InvalidUrl {
url: String,
} {
description("invalid url")
display("invalid url: {}", url)
}
RunningCommand {
name: OsString,
} {
description("command failed")
display("command failed: '{}'", PathBuf::from(name).display())
}
NotAFile {
path: PathBuf,
} {
description("not a file")
display("not a file: '{}'", path.display())
}
NotADirectory {
path: PathBuf,
} {
description("not a directory")
display("not a directory: '{}'", path.display())
}
LinkingFile {
src: PathBuf,
dest: PathBuf,
} {
description("could not link file")
display("could not create link from '{}' to '{}'", src.display(), dest.display())
}
LinkingDirectory {
src: PathBuf,
dest: PathBuf,
} {
description("could not symlink directory")
display("could not create link from '{}' to '{}'", src.display(), dest.display())
}
CopyingDirectory {
src: PathBuf,
dest: PathBuf,
} {
description("could not copy directory")
display("could not copy directory from '{}' to '{}'", src.display(), dest.display())
}
CopyingFile {
src: PathBuf,
dest: PathBuf,
} {
description("could not copy file")
display("could not copy file from '{}' to '{}'", src.display(), dest.display())
}
RemovingFile {
name: &'static str,
path: PathBuf,
} {
description("could not remove file")
display("could not remove '{}' file: '{}'", name, path.display())
}
RemovingDirectory {
name: &'static str,
path: PathBuf,
} {
description("could not remove directory")
display("could not remove '{}' directory: '{}'", name, path.display())
}
SettingPermissions {
path: PathBuf,
} {
description("failed to set permissions")
display("failed to set permissions for '{}'", path.display())
}
GettingCwd {
description("couldn't get current working directory")
}
CargoHome {
description("couldn't find value of CARGO_HOME")
}
RustupHome {
description("couldn't find value of RUSTUP_HOME")
}
InvalidToolchainName(t: String) {
description("invalid toolchain name")
display("invalid toolchain name: '{}'", t)
}
InvalidCustomToolchainName(t: String) {
description("invalid custom toolchain name")
display("invalid custom toolchain name: '{}'", t)
}
ChecksumFailed {
url: String,
expected: String,
calculated: String,
} {
description("checksum failed")
display("checksum failed, expected: '{}', calculated: '{}'",
expected,
calculated)
}
ComponentConflict {
name: String,
path: PathBuf,
} {
description("conflicting component")
display("failed to install component: '{}', detected conflict: '{:?}'",
name,
path)
}
ComponentMissingFile {
name: String,
path: PathBuf,
} {
description("missing file in component")
display("failure removing component '{}', directory does not exist: '{:?}'",
name,
path)
}
ComponentMissingDir {
name: String,
path: PathBuf,
} {
description("missing directory in component")
display("failure removing component '{}', directory does not exist: '{:?}'",
name,
path)
}
CorruptComponent(name: String) {
description("corrupt component manifest")
display("component manifest for '{}' is corrupt", name)
}
ExtractingPackage {
description("failed to extract package (perhaps you ran out of disk space?)")
}
BadInstallerVersion(v: String) {
description("unsupported installer version")
display("unsupported installer version: {}", v)
}
BadInstalledMetadataVersion(v: String) {
description("unsupported metadata version in existing installation")
display("unsupported metadata version in existing installation: {}", v)
}
ComponentDirPermissionsFailed {
description("I/O error walking directory during install")
}
ComponentFilePermissionsFailed {
description("error setting file permissions during install")
}
ComponentDownloadFailed(c: String) {
description("component download failed")
display("component download failed for {}", c)
}
Parsing(e: toml::de::Error) {
description("error parsing manifest")
}
UnsupportedVersion(v: String) {
description("unsupported manifest version")
display("manifest version '{}' is not supported", v)
}
MissingPackageForComponent(name: String) {
description("missing package for component")
display("server sent a broken manifest: missing package for component {}", name)
}
MissingPackageForRename(name: String) {
description("missing package for the target of a rename")
display("server sent a broken manifest: missing package for the target of a rename {}", name)
}
RequestedComponentsUnavailable(c: Vec<Component>, manifest: Manifest, toolchain: String) {
description("some requested components are unavailable to download")
display("{} for channel '{}'\n{}", component_unavailable_msg(&c, &manifest), toolchain, TOOLSTATE_MSG)
}
UnknownMetadataVersion(v: String) {
description("unknown metadata version")
display("unknown metadata version: '{}'", v)
}
ToolchainNotInstalled(t: String) {
description("toolchain is not installed")
display("toolchain '{}' is not installed", t)
}
OverrideToolchainNotInstalled(t: String) {
description("override toolchain is not installed")
display("override toolchain '{}' is not installed", t)
}
BinaryNotFound(bin: String, t: String, is_default: bool) {
description("toolchain does not contain binary")
display("'{}' is not installed for the toolchain '{}'{}", bin, t, install_msg(bin, t, *is_default))
}
NeedMetadataUpgrade {
description("rustup's metadata is out of date. run `rustup self upgrade-data`")
}
UpgradeIoError {
description("I/O error during upgrade")
}
BadInstallerType(s: String) {
description("invalid extension for installer")
display("invalid extension for installer: '{}'", s)
}
ComponentsUnsupported(t: String) {
description("toolchain does not support components")
display("toolchain '{}' does not support components", t)
}
UnknownComponent(t: String, c: String, s: Option<String>) {
description("toolchain does not contain component")
display("toolchain '{}' does not contain component {}{}", t, c, if let Some(suggestion) = s {
format!("; did you mean '{}'?", suggestion)
} else {
"".to_string()
})
}
AddingRequiredComponent(t: String, c: String) {
description("required component cannot be added")
display("component {} was automatically added because it is required for toolchain '{}'",
c, t)
}
ParsingSettings(e: toml::de::Error) {
description("error parsing settings")
}
RemovingRequiredComponent(t: String, c: String) {
description("required component cannot be removed")
display("component {} is required for toolchain '{}' and cannot be removed",
c, t)
}
NoExeName {
description("couldn't determine self executable name")
}
UnsupportedKind(v: String) {
description("unsupported tar entry")
display("tar entry kind '{}' is not supported", v)
}
BadPath(v: PathBuf) {
description("bad path in tar")
display("tar path '{}' is not supported", v.display())
}
}
}
fn component_unavailable_msg(cs: &[Component], manifest: &Manifest) -> String {
assert!(!cs.is_empty());
let mut buf = vec![];
if cs.len() == 1 {
let _ = write!(
buf,
"component {} is unavailable for download",
&cs[0].description(manifest)
);
} else {
let same_target = cs
.iter()
.all(|c| c.target == cs[0].target || c.target.is_none());
if same_target {
let cs_str = cs
.iter()
.map(|c| format!("'{}'", c.short_name(manifest)))
.collect::<Vec<_>>()
.join(", ");
let _ = write!(buf, "some components unavailable for download: {}", cs_str,);
} else {
let cs_str = cs
.iter()
.map(|c| c.description(manifest))
.collect::<Vec<_>>()
.join(", ");
let _ = write!(buf, "some components unavailable for download: {}", cs_str,);
}
}
String::from_utf8(buf).expect("")
}
fn install_msg(bin: &str, toolchain: &str, is_default: bool) -> String {
match component_for_bin(bin) {
Some(c) => format!("\nTo install, run `rustup component add {}{}`", c, {
if is_default {
String::new()
} else {
format!(" --toolchain {}", toolchain)
}
}),
None => String::new(),
}
}