Lazy remote files in the browser (M4), SWMR reader (M5), Python remote reads and editing #19
@@ -832,10 +832,23 @@ impl FileEditor {
|
|||||||
Ok(f)
|
Ok(f)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A reader over the held file itself for planning an edit (it shares
|
/// A reader over the held file for planning an edit (dropped before the
|
||||||
/// the file's lock, and is dropped before the edit writes).
|
/// edit writes). On Linux a new open file description through
|
||||||
|
/// `/proc/self/fd`: a mapping of a clone of the held descriptor would
|
||||||
|
/// share its `flock`, and a process forked meanwhile (any
|
||||||
|
/// `std::process::Command` on another thread) would briefly keep the
|
||||||
|
/// lock alive after the editor is dropped. Elsewhere a clone of the
|
||||||
|
/// held descriptor, which follows the file wherever its path goes.
|
||||||
fn plan_reader(&self) -> Result<File, Error> {
|
fn plan_reader(&self) -> Result<File, Error> {
|
||||||
let dir = self.path.parent().map(Path::to_path_buf);
|
let dir = self.path.parent().map(Path::to_path_buf);
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
{
|
||||||
|
use std::os::fd::AsRawFd;
|
||||||
|
let proc = format!("/proc/self/fd/{}", self.file.as_raw_fd());
|
||||||
|
if let Ok(f) = std::fs::File::open(proc) {
|
||||||
|
return File::from_std_file(f, dir);
|
||||||
|
}
|
||||||
|
}
|
||||||
File::from_std_file(self.file.try_clone()?, dir)
|
File::from_std_file(self.file.try_clone()?, dir)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user