media-converter: Fix read-only DB detection
This commit is contained in:
parent
a4824da779
commit
7195a2c542
3 changed files with 10 additions and 9 deletions
|
@ -211,7 +211,7 @@ impl AudioConverterDumpFozdb {
|
|||
return self;
|
||||
}
|
||||
|
||||
match fossilize::StreamArchive::new(&dump_file_path, OpenOptions::new().write(true).read(true).create(create), AUDIOCONV_FOZ_NUM_TAGS) {
|
||||
match fossilize::StreamArchive::new(&dump_file_path, OpenOptions::new().write(true).read(true).create(create), false /* read-only? */, AUDIOCONV_FOZ_NUM_TAGS) {
|
||||
Ok(newdb) => {
|
||||
self.fozdb = Some(newdb);
|
||||
},
|
||||
|
@ -237,7 +237,7 @@ impl AudioConverterDumpFozdb {
|
|||
}
|
||||
if let Some(fozdb) = &mut self.open(false).fozdb {
|
||||
if let Ok(read_fozdb_path) = std::env::var("MEDIACONV_AUDIO_TRANSCODED_FILE") {
|
||||
if let Ok(read_fozdb) = fossilize::StreamArchive::new(&read_fozdb_path, OpenOptions::new().read(true), AUDIOCONV_FOZ_NUM_TAGS) {
|
||||
if let Ok(read_fozdb) = fossilize::StreamArchive::new(&read_fozdb_path, OpenOptions::new().read(true), true /* read-only? */, AUDIOCONV_FOZ_NUM_TAGS) {
|
||||
let mut chunks_to_discard = HashSet::<(u32, u128)>::new();
|
||||
let mut chunks_to_keep = HashSet::<(u32, u128)>::new();
|
||||
|
||||
|
@ -559,7 +559,7 @@ impl AudioConvState {
|
|||
loggable_error!(CAT, "MEDIACONV_AUDIO_TRANSCODED_FILE is not set!")
|
||||
})?;
|
||||
|
||||
let read_fozdb = match fossilize::StreamArchive::new(&read_fozdb_path, OpenOptions::new().read(true), AUDIOCONV_FOZ_NUM_TAGS) {
|
||||
let read_fozdb = match fossilize::StreamArchive::new(&read_fozdb_path, OpenOptions::new().read(true), true /* read-only? */, AUDIOCONV_FOZ_NUM_TAGS) {
|
||||
Ok(s) => Some(s),
|
||||
Err(_) => None,
|
||||
};
|
||||
|
|
|
@ -197,6 +197,7 @@ impl PayloadEntry {
|
|||
|
||||
pub struct StreamArchive {
|
||||
file: fs::File,
|
||||
read_only: bool,
|
||||
|
||||
seen_blobs: Vec<HashMap<FossilizeHash, PayloadEntry>>,
|
||||
|
||||
|
@ -210,7 +211,7 @@ pub enum CRCCheck {
|
|||
|
||||
impl StreamArchive {
|
||||
|
||||
pub fn new<P: AsRef<std::path::Path>>(filename: P, fileopts: &OpenOptions, num_tags: usize) -> Result<Self, Error> {
|
||||
pub fn new<P: AsRef<std::path::Path>>(filename: P, fileopts: &OpenOptions, read_only: bool, num_tags: usize) -> Result<Self, Error> {
|
||||
|
||||
let file = fileopts.open(filename)?;
|
||||
|
||||
|
@ -221,6 +222,7 @@ impl StreamArchive {
|
|||
|
||||
let mut ret = Self {
|
||||
file,
|
||||
read_only,
|
||||
seen_blobs,
|
||||
write_pos: 0,
|
||||
};
|
||||
|
@ -272,8 +274,7 @@ impl StreamArchive {
|
|||
match res {
|
||||
Ok(p) => {
|
||||
self.write_pos = p;
|
||||
if tag >= self.seen_blobs.len() &&
|
||||
self.file.metadata()?.permissions().readonly() {
|
||||
if tag >= self.seen_blobs.len() && self.read_only {
|
||||
/* ignore unknown tags for read-only DBs, otherwise panic */
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -138,7 +138,7 @@ impl VideoConverterDumpFozdb {
|
|||
return self;
|
||||
}
|
||||
|
||||
match fossilize::StreamArchive::new(&dump_file_path, OpenOptions::new().write(true).read(true).create(create), VIDEOCONV_FOZ_NUM_TAGS) {
|
||||
match fossilize::StreamArchive::new(&dump_file_path, OpenOptions::new().write(true).read(true).create(create), false /* read-only? */, VIDEOCONV_FOZ_NUM_TAGS) {
|
||||
Ok(newdb) => {
|
||||
self.fozdb = Some(newdb);
|
||||
},
|
||||
|
@ -164,7 +164,7 @@ impl VideoConverterDumpFozdb {
|
|||
}
|
||||
if let Some(fozdb) = &mut self.open(false).fozdb {
|
||||
if let Ok(read_fozdb_path) = std::env::var("MEDIACONV_VIDEO_TRANSCODED_FILE") {
|
||||
if let Ok(read_fozdb) = fossilize::StreamArchive::new(&read_fozdb_path, OpenOptions::new().read(true), VIDEOCONV_FOZ_NUM_TAGS) {
|
||||
if let Ok(read_fozdb) = fossilize::StreamArchive::new(&read_fozdb_path, OpenOptions::new().read(true), true /* read-only? */, VIDEOCONV_FOZ_NUM_TAGS) {
|
||||
let mut chunks = Vec::<(u32, u128)>::new();
|
||||
|
||||
for stream_id in fozdb.iter_tag(VIDEOCONV_FOZ_TAG_STREAM).cloned().collect::<Vec<u128>>() {
|
||||
|
@ -306,7 +306,7 @@ impl VideoConvState {
|
|||
loggable_error!(CAT, "MEDIACONV_VIDEO_TRANSCODED_FILE is not set!")
|
||||
})?;
|
||||
|
||||
let read_fozdb = match fossilize::StreamArchive::new(&read_fozdb_path, OpenOptions::new().read(true), VIDEOCONV_FOZ_NUM_TAGS) {
|
||||
let read_fozdb = match fossilize::StreamArchive::new(&read_fozdb_path, OpenOptions::new().read(true), true /* read-only? */, VIDEOCONV_FOZ_NUM_TAGS) {
|
||||
Ok(s) => Some(s),
|
||||
Err(_) => None,
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue