]> git.lizzy.rs Git - rust.git/commitdiff
Pick the last version of the different files if there is more than one
authorGuillaume Gomez <guillaume1.gomez@gmail.com>
Sat, 21 Mar 2020 12:48:10 +0000 (13:48 +0100)
committerGuillaume Gomez <guillaume1.gomez@gmail.com>
Sat, 21 Mar 2020 12:48:10 +0000 (13:48 +0100)
src/tools/rustdoc-js-std/tester.js

index f34e702e85e2848aeea3cffbf0ac63d973451695..affdcc7f4b759c1445b8a212715426b22fc6de6a 100644 (file)
@@ -2,8 +2,10 @@ const fs = require('fs');
 const path = require('path');
 const tools = require('../rustdoc-js-common/lib.js');
 
+
 function findFile(dir, name, extension) {
     var entries = fs.readdirSync(dir);
+    var matches = [];
     for (var i = 0; i < entries.length; ++i) {
         var entry = entries[i];
         var file_type = fs.statSync(dir + entry);
@@ -11,10 +13,28 @@ function findFile(dir, name, extension) {
             continue;
         }
         if (entry.startsWith(name) && entry.endsWith(extension)) {
-            return entry;
+            var version = entry.slice(name.length, entry.length - extension.length);
+            version = version.split(".").map(function(x) {
+                return parseInt(x);
+            });
+            var total = 0;
+            var mult = 1;
+            for (var j = version.length - 1; j >= 0; --j) {
+                total += version[j] * mult;
+                mult *= 1000;
+            }
+            matches.push([entry, total]);
         }
     }
-    return null;
+    if (matches.length === 0) {
+        return null;
+    }
+    // We make a reverse sort to have the "highest" file. Very useful in case you didn't clean up
+    // you std doc folder...
+    matches.sort(function(a, b) {
+        return b[1] - a[1];
+    });
+    return matches[0][0];
 }
 
 function readFileMatching(dir, name, extension) {