Browse Source

Guard from more non-existent directories errors (#79)

remotes/origin/add-simple-redirecting-site
Gal Schlezinger 6 years ago committed by GitHub
parent
commit
478145082a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      library/Fs.re
  2. 14
      library/Versions.re

6
library/Fs.re

@ -35,4 +35,10 @@ let writeFile = (path, contents) => { @@ -35,4 +35,10 @@ let writeFile = (path, contents) => {
Lwt.return();
};
let exists = path => {
try%lwt (Lwt_unix.file_exists(path)) {
| Unix.Unix_error(_, _, _) => Lwt.return(false)
};
};
let realpath = Filename.realpath;

14
library/Versions.re

@ -36,9 +36,13 @@ module Local = { @@ -36,9 +36,13 @@ module Local = {
let getLatestInstalledNameByPrefix = prefix => {
open Lwt;
let%lwt versions =
Fs.readdir(Directories.nodeVersions)
>|= List.filter(isVersionFitsPrefix(prefix))
>|= List.sort(flip(compare));
Lwt.catch(
() =>
Fs.readdir(Directories.nodeVersions)
>|= List.filter(isVersionFitsPrefix(prefix))
>|= List.sort(flip(compare)),
_ => Lwt.return_nil,
);
switch (versions) {
| [version, ...xs] => Lwt.return_some(version)
| [] => Lwt.return_none
@ -291,8 +295,8 @@ let parse = version => { @@ -291,8 +295,8 @@ let parse = version => {
let aliasPath = Aliases.toDirectory(version);
let versionPath = Local.toDirectory(formattedVersion);
let%lwt aliasExists = Lwt_unix.file_exists(aliasPath)
and versionExists = Lwt_unix.file_exists(versionPath)
let%lwt aliasExists = Fs.exists(aliasPath)
and versionExists = Fs.exists(versionPath)
and versionByPrefixPath =
Local.getLatestInstalledNameByPrefix(formattedVersion);

Loading…
Cancel
Save