mirror of
https://github.com/encounter/decomp-toolkit.git
synced 2025-12-11 22:44:15 +00:00
rel make: Avoid EMFILE when loading many modules (#122)
This commit is contained in:
@@ -300,7 +300,15 @@ fn make(args: MakeArgs) -> Result<()> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Load all modules
|
// Load all modules
|
||||||
let mut files = paths.iter().map(|p| open_file(p, true)).collect::<Result<Vec<_>>>()?;
|
let mut files = paths
|
||||||
|
.iter()
|
||||||
|
.map(|p| {
|
||||||
|
let mut file = open_file(p, true)?;
|
||||||
|
// Immediately map to avoid keeping file handles open
|
||||||
|
file.map()?;
|
||||||
|
Ok(file)
|
||||||
|
})
|
||||||
|
.collect::<Result<Vec<_>>>()?;
|
||||||
let modules = files
|
let modules = files
|
||||||
.par_iter_mut()
|
.par_iter_mut()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
|
|||||||
@@ -86,14 +86,17 @@ impl Seek for StdFile {
|
|||||||
|
|
||||||
impl VfsFile for StdFile {
|
impl VfsFile for StdFile {
|
||||||
fn map(&mut self) -> io::Result<&[u8]> {
|
fn map(&mut self) -> io::Result<&[u8]> {
|
||||||
let file = match self.file {
|
|
||||||
Some(ref mut file) => file,
|
|
||||||
None => self.file.insert(BufReader::new(fs::File::open(&self.path)?)),
|
|
||||||
};
|
|
||||||
let mmap = match self.mmap {
|
let mmap = match self.mmap {
|
||||||
Some(ref mmap) => mmap,
|
Some(ref mmap) => mmap,
|
||||||
None => self.mmap.insert(unsafe { memmap2::Mmap::map(file.get_ref())? }),
|
None => {
|
||||||
|
let file = match self.file {
|
||||||
|
Some(ref mut file) => file,
|
||||||
|
None => self.file.insert(BufReader::new(fs::File::open(&self.path)?)),
|
||||||
|
};
|
||||||
|
self.mmap.insert(unsafe { memmap2::Mmap::map(file.get_ref())? })
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
self.file = None; // Drop the BufReader to avoid holding the file handle
|
||||||
Ok(mmap)
|
Ok(mmap)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user