From f05d041c02652f16253c11989c581de75d55b738 Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Thu, 29 Oct 2020 15:26:36 -0700 Subject: [PATCH] Handle duplicate files on web when they're both bundled in and uploaded to S3. In particular, don't crash on the all city picker on web. --- abstutil/src/io_web.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/abstutil/src/io_web.rs b/abstutil/src/io_web.rs index 702931ad6e..5d1903abe9 100644 --- a/abstutil/src/io_web.rs +++ b/abstutil/src/io_web.rs @@ -1,6 +1,7 @@ //! Since the local filesystem can't be read from a web browser, instead bundle system data files in //! the WASM binary using include_dir. For now, no support for saving files. +use std::collections::BTreeSet; use std::error::Error; use serde::de::DeserializeOwned; @@ -34,25 +35,24 @@ pub fn file_exists>(path: I) -> bool { } pub fn list_dir(dir: String) -> Vec { - let mut results = Vec::new(); + let mut results = BTreeSet::new(); if let Some(dir) = SYSTEM_DATA.get_dir(dir.trim_start_matches("../data/system/")) { for f in dir.files() { - results.push(format!("../data/system/{}", f.path().display())); + results.insert(format!("../data/system/{}", f.path().display())); } } else { error!("Can't list_dir({})", dir); } - // Merge with remote files + // Merge with remote files. Duplicates handled by BTreeSet. let dir = dir.trim_start_matches("../"); for f in Manifest::load().entries.keys() { if f.starts_with(dir) { - results.push(format!("../{}", f)); + results.insert(format!("../{}", f)); } } - results.sort(); - results + results.into_iter().collect() } pub fn slurp_file(path: &str) -> Result, Box> { @@ -75,7 +75,7 @@ pub fn maybe_read_binary( } pub fn write_json(_path: String, _obj: &T) { - // TODO not yet + // TODO } pub fn write_binary(_path: String, _obj: &T) {