Skip to content

Commit 554ada3

Browse files
committed
1 parent a2aa60b commit 554ada3

File tree

1 file changed

+26
-44
lines changed

1 file changed

+26
-44
lines changed

godot-core/src/tools/gfile.rs

Lines changed: 26 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,10 @@ impl GFile {
106106
arg_into_ref!(path);
107107

108108
let fa = FileAccess::open(path, flags).ok_or_else(|| {
109-
std::io::Error::new(
110-
ErrorKind::Other,
111-
format!(
112-
"can't open file {path} in mode {flags:?}; GodotError: {:?}",
113-
FileAccess::get_open_error()
114-
),
115-
)
109+
std::io::Error::other(format!(
110+
"can't open file {path} in mode {flags:?}; GodotError: {:?}",
111+
FileAccess::get_open_error()
112+
))
116113
})?;
117114

118115
Ok(Self::from_inner(fa))
@@ -133,13 +130,10 @@ impl GFile {
133130
.compression_mode(compression_mode)
134131
.done()
135132
.ok_or_else(|| {
136-
std::io::Error::new(
137-
ErrorKind::Other,
138-
format!(
139-
"can't open file {path} in mode {flags:?}; GodotError: {:?}",
140-
FileAccess::get_open_error()
141-
),
142-
)
133+
std::io::Error::other(format!(
134+
"can't open file {path} in mode {flags:?}; GodotError: {:?}",
135+
FileAccess::get_open_error()
136+
))
143137
})?;
144138

145139
Ok(Self::from_inner(fa))
@@ -157,13 +151,10 @@ impl GFile {
157151
arg_into_ref!(path);
158152

159153
let fa = FileAccess::open_encrypted(path, flags, key).ok_or_else(|| {
160-
std::io::Error::new(
161-
ErrorKind::Other,
162-
format!(
163-
"can't open file {path} in mode {flags:?}; GodotError: {:?}",
164-
FileAccess::get_open_error()
165-
),
166-
)
154+
std::io::Error::other(format!(
155+
"can't open file {path} in mode {flags:?}; GodotError: {:?}",
156+
FileAccess::get_open_error()
157+
))
167158
})?;
168159

169160
Ok(Self::from_inner(fa))
@@ -182,13 +173,10 @@ impl GFile {
182173
arg_into_ref!(password);
183174

184175
let fa = FileAccess::open_encrypted_with_pass(path, flags, password).ok_or_else(|| {
185-
std::io::Error::new(
186-
ErrorKind::Other,
187-
format!(
188-
"can't open file {path} in mode {flags:?}; GodotError: {:?}",
189-
FileAccess::get_open_error()
190-
),
191-
)
176+
std::io::Error::other(format!(
177+
"can't open file {path} in mode {flags:?}; GodotError: {:?}",
178+
FileAccess::get_open_error()
179+
))
192180
})?;
193181
Ok(Self::from_inner(fa))
194182
}
@@ -224,10 +212,9 @@ impl GFile {
224212
let modified_time = FileAccess::get_modified_time(path);
225213

226214
if modified_time == 0 {
227-
Err(std::io::Error::new(
228-
ErrorKind::Other,
229-
format!("can't retrieve last modified time: {path}"),
230-
))
215+
Err(std::io::Error::other(format!(
216+
"can't retrieve last modified time: {path}"
217+
)))
231218
} else {
232219
Ok(modified_time)
233220
}
@@ -240,10 +227,9 @@ impl GFile {
240227
let md5 = FileAccess::get_md5(path);
241228

242229
if md5.is_empty() {
243-
Err(std::io::Error::new(
244-
ErrorKind::Other,
245-
format!("failed to compute file's MD5 checksum: {path}"),
246-
))
230+
Err(std::io::Error::other(format!(
231+
"failed to compute file's MD5 checksum: {path}"
232+
)))
247233
} else {
248234
Ok(md5)
249235
}
@@ -256,10 +242,9 @@ impl GFile {
256242
let sha256 = FileAccess::get_sha256(path);
257243

258244
if sha256.is_empty() {
259-
Err(std::io::Error::new(
260-
ErrorKind::Other,
261-
format!("failed to compute file's SHA-256 checksum: {path}"),
262-
))
245+
Err(std::io::Error::other(format!(
246+
"failed to compute file's SHA-256 checksum: {path}"
247+
)))
263248
} else {
264249
Ok(sha256)
265250
}
@@ -684,10 +669,7 @@ impl GFile {
684669
return Ok(());
685670
}
686671

687-
Err(std::io::Error::new(
688-
ErrorKind::Other,
689-
format!("GodotError: {:?}", error),
690-
))
672+
Err(std::io::Error::other(format!("GodotError: {:?}", error)))
691673
}
692674

693675
// File length cache is stored and kept when possible because `FileAccess::get_length()` turned out to be slowing down

0 commit comments

Comments
 (0)