summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2021-06-25 21:44:27 -0400
committerGitHub <noreply@github.com>2021-06-25 21:44:27 -0400
commit1f4cdc067a4e26921ee53d58751bb60279d3cab2 (patch)
treea361a4ad3956f80e062eb5cd9a69c41faca47d9d
parent2f1ac460912f0faf3806e320b287573d1af762aa (diff)
fix(lsp): reload import registries should not error when the module registries directory does not exist (#11123)
-rw-r--r--cli/fs_util.rs10
-rw-r--r--cli/lsp/language_server.rs3
2 files changed, 12 insertions, 1 deletions
diff --git a/cli/fs_util.rs b/cli/fs_util.rs
index a862e4bd3..462bbdddb 100644
--- a/cli/fs_util.rs
+++ b/cli/fs_util.rs
@@ -161,6 +161,16 @@ where
Ok(target_files)
}
+// Asynchronously removes a directory and all its descendants, but does not error
+// when the directory does not exist.
+pub async fn remove_dir_all_if_exists(path: &Path) -> std::io::Result<()> {
+ let result = tokio::fs::remove_dir_all(path).await;
+ match result {
+ Err(err) if err.kind() == std::io::ErrorKind::NotFound => Ok(()),
+ _ => result,
+ }
+}
+
#[cfg(test)]
mod tests {
use super::*;
diff --git a/cli/lsp/language_server.rs b/cli/lsp/language_server.rs
index 1bbb8c92e..ab1b6ccd4 100644
--- a/cli/lsp/language_server.rs
+++ b/cli/lsp/language_server.rs
@@ -54,6 +54,7 @@ use super::urls;
use crate::config_file::ConfigFile;
use crate::config_file::TsConfig;
use crate::deno_dir;
+use crate::fs_util;
use crate::import_map::ImportMap;
use crate::logger;
use crate::media_type::MediaType;
@@ -2410,7 +2411,7 @@ impl Inner {
}
async fn reload_import_registries(&mut self) -> LspResult<Option<Value>> {
- fs::remove_dir_all(&self.module_registries_location)
+ fs_util::remove_dir_all_if_exists(&self.module_registries_location)
.await
.map_err(|err| {
error!("Unable to remove registries cache: {}", err);