Skip to content

Commit daeb4d2

Browse files
committed
Remove PREFIX option to add-directory
Previously, it could be used inconsistently with the CRATESFYI_PREFIX environment variable, which was confusing.
1 parent 33ddc64 commit daeb4d2

File tree

3 files changed

+7
-10
lines changed

3 files changed

+7
-10
lines changed

src/bin/cratesfyi.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -388,9 +388,6 @@ enum DatabaseSubcommand {
388388
/// Path of file or directory
389389
#[structopt(name = "DIRECTORY")]
390390
directory: PathBuf,
391-
/// Prefix of files in database
392-
#[structopt(name = "PREFIX", env = "CRATESFYI_PREFIX")]
393-
prefix: String,
394391
},
395392

396393
/// Remove documentation from the database
@@ -440,8 +437,8 @@ impl DatabaseSubcommand {
440437
)?;
441438
}
442439

443-
Self::AddDirectory { directory, prefix } => {
444-
add_path_into_database(&*ctx.storage()?, &prefix, directory)
440+
Self::AddDirectory { directory } => {
441+
add_path_into_database(&*ctx.storage()?, &ctx.config()?.prefix, directory)
445442
.context("Failed to add directory into database")?;
446443
}
447444

src/db/file.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ use std::path::{Path, PathBuf};
2424
/// and files generated by rustdoc.
2525
pub fn add_path_into_database<P: AsRef<Path>>(
2626
storage: &Storage,
27-
prefix: &str,
27+
prefix: impl AsRef<Path>,
2828
path: P,
2929
) -> Result<(Value, CompressionAlgorithms)> {
30-
let (file_list, algorithms) = storage.store_all(prefix, path.as_ref())?;
30+
let (file_list, algorithms) = storage.store_all(prefix.as_ref(), path.as_ref())?;
3131
Ok((
3232
file_list_to_json(file_list.into_iter().collect()),
3333
algorithms,

src/storage/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ impl Storage {
152152
// This returns (map<filename, mime type>, set<compression algorithms>).
153153
pub(crate) fn store_all(
154154
&self,
155-
prefix: &str,
155+
prefix: &Path,
156156
root_dir: &Path,
157157
) -> Result<(HashMap<PathBuf, String>, HashSet<CompressionAlgorithm>), Error> {
158158
let mut file_paths_and_mimes = HashMap::new();
@@ -171,7 +171,7 @@ impl Storage {
171171
.map(|(file_path, file)| -> Result<_, Error> {
172172
let alg = CompressionAlgorithm::default();
173173
let content = compress(file, alg)?;
174-
let bucket_path = Path::new(prefix).join(&file_path).to_slash().unwrap();
174+
let bucket_path = prefix.join(&file_path).to_slash().unwrap();
175175

176176
let mime = detect_mime(&file_path);
177177
file_paths_and_mimes.insert(file_path, mime.to_string());
@@ -464,7 +464,7 @@ mod backend_tests {
464464
fs::write(path, "data")?;
465465
}
466466

467-
let (stored_files, algs) = storage.store_all("prefix", dir.path())?;
467+
let (stored_files, algs) = storage.store_all(Path::new("prefix"), dir.path())?;
468468
assert_eq!(stored_files.len(), files.len());
469469
for name in &files {
470470
let name = Path::new(name);

0 commit comments

Comments
 (0)