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. 10
      library/Versions.re

6
library/Fs.re

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

10
library/Versions.re

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

Loading…
Cancel
Save