mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-29 16:45:30 +08:00
Merge #3528
3528: Fix a bug where the filestore could try to parse its own tmp file and fail r=irevoire a=irevoire Fixes #3502 The bug is that, while receiving an update, the file store create a temporary file named something like `.tmpX123Y456Z`. And then, when asking for the list of uuids available in the task store, we were trying to parse this kind of filename as an `uuidv4` instead of ignoring them. This bug has been introduced in the v1.0 of meilisearch and only affects the global stats route. Co-authored-by: Tamo <tamo@meilisearch.com>
This commit is contained in:
commit
b43b4cf4b9
@ -116,10 +116,20 @@ impl FileStore {
|
|||||||
|
|
||||||
/// List the Uuids of the files in the FileStore
|
/// List the Uuids of the files in the FileStore
|
||||||
pub fn all_uuids(&self) -> Result<impl Iterator<Item = Result<Uuid>>> {
|
pub fn all_uuids(&self) -> Result<impl Iterator<Item = Result<Uuid>>> {
|
||||||
Ok(self.path.read_dir()?.map(|entry| {
|
Ok(self.path.read_dir()?.filter_map(|entry| {
|
||||||
Ok(Uuid::from_str(
|
let file_name = match entry {
|
||||||
entry?.file_name().to_str().ok_or(Error::CouldNotParseFileNameAsUtf8)?,
|
Ok(entry) => entry.file_name(),
|
||||||
)?)
|
Err(e) => return Some(Err(e.into())),
|
||||||
|
};
|
||||||
|
let file_name = match file_name.to_str() {
|
||||||
|
Some(file_name) => file_name,
|
||||||
|
None => return Some(Err(Error::CouldNotParseFileNameAsUtf8)),
|
||||||
|
};
|
||||||
|
if file_name.starts_with('.') {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(Uuid::from_str(file_name).map_err(|e| e.into()))
|
||||||
|
}
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -135,3 +145,34 @@ impl File {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test {
|
||||||
|
use std::io::Write;
|
||||||
|
|
||||||
|
use tempfile::TempDir;
|
||||||
|
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn all_uuids() {
|
||||||
|
let dir = TempDir::new().unwrap();
|
||||||
|
let fs = FileStore::new(dir.path()).unwrap();
|
||||||
|
let (uuid, mut file) = fs.new_update().unwrap();
|
||||||
|
file.write_all(b"Hello world").unwrap();
|
||||||
|
file.persist().unwrap();
|
||||||
|
let all_uuids = fs.all_uuids().unwrap().collect::<Result<Vec<_>>>().unwrap();
|
||||||
|
assert_eq!(all_uuids, vec![uuid]);
|
||||||
|
|
||||||
|
let (uuid2, file) = fs.new_update().unwrap();
|
||||||
|
let all_uuids = fs.all_uuids().unwrap().collect::<Result<Vec<_>>>().unwrap();
|
||||||
|
assert_eq!(all_uuids, vec![uuid]);
|
||||||
|
|
||||||
|
file.persist().unwrap();
|
||||||
|
let mut all_uuids = fs.all_uuids().unwrap().collect::<Result<Vec<_>>>().unwrap();
|
||||||
|
all_uuids.sort();
|
||||||
|
let mut expected = vec![uuid, uuid2];
|
||||||
|
expected.sort();
|
||||||
|
assert_eq!(all_uuids, expected);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user