Fixing a deadlock in working_copy::memory (used only in tests for now)

[?]
Apr 29, 2021, 2:31 PM
MOPABMFWZOEMCIQMLEFH74NGTFV6K26FGUFETV3FG5VHCBGLXDIQC

Dependencies

  • [2] I24UEJQL Various post-fire fixes
  • [3] VO5OQW4W Removing anyhow in libpijul
  • [4] X7OHUPL5 Fixing a bug in unrecord, and fixing the tests
  • [5] SXEYMYF7 Fixing the bad changes in history (unfortunately, by rebooting).

Change contents

  • replacement in libpijul/src/working_copy/memory.rs at line 77
    [3.201085][3.201085:201154]()
    pub fn add_file(&mut self, file: &str, file_contents: Vec<u8>) {
    [3.201085]
    [3.0]
    pub fn add_file(&self, file: &str, file_contents: Vec<u8>) {
  • replacement in libpijul/src/working_copy/memory.rs at line 90
    [3.201461][3.201461:201505]()
    pub fn add_dir(&mut self, file: &str) {
    [3.201461]
    [3.55]
    pub fn add_dir(&self, file: &str) {
  • replacement in libpijul/src/working_copy/memory.rs at line 218
    [2.25912][2.25912:25992]()
    let m = self.0.lock().unwrap();
    if m.get_file(file).is_none() {
    [2.25912]
    [3.205553]
    let not_already_exists = {
    let m = self.0.lock().unwrap();
    m.get_file(file).is_none()
    };
    if not_already_exists {
  • replacement in libpijul/src/working_copy/memory.rs at line 272
    [3.207262][2.26520:26615]()
    let mut m = self.0.lock().unwrap();
    if let Some(inode) = m.remove_path_(old) {
    [3.207262]
    [3.207316]
    let inode = {
    let mut m = self.0.lock().unwrap();
    m.remove_path_(old)
    };
    if let Some(inode) = inode {
  • replacement in libpijul/src/working_copy/memory.rs at line 299
    [2.26935][2.26935:26972](),[2.26972][3.208166:208254](),[3.208166][3.208166:208254]()
    match m.get_file_mut(file) {
    Some(Inode::File {
    ref mut contents, ..
    }) => {
    [2.26935]
    [2.26973]
    if let Some(f) = m.get_file_mut(file) {
    if let Inode::File { ref mut contents, .. } = f {
  • replacement in libpijul/src/working_copy/memory.rs at line 302
    [2.27023][2.27023:27051]()
    Ok(Writer {
    [2.27023]
    [2.27051]
    return Ok(Writer {
  • replacement in libpijul/src/working_copy/memory.rs at line 305
    [3.3127][3.208321:208357](),[2.27111][3.208321:208357](),[3.208321][3.208321:208357](),[3.208357][2.27112:27177](),[2.27177][3.208404:208459](),[3.208404][3.208404:208459](),[3.3199][3.208507:208599](),[3.208507][3.208507:208599](),[3.208599][3.400:460](),[3.460][2.27178:27230](),[2.27230][3.208697:208778](),[3.208697][3.208697:208778](),[3.208778][2.27231:27274]()
    }
    None => {
    let contents = Arc::new(Mutex::new(Vec::new()));
    let last_modified = SystemTime::now();
    self.add_inode(
    file,
    Inode::File {
    meta: InodeMetadata::new(0, false),
    contents: contents.clone(),
    last_modified,
    },
    );
    Ok(Writer { w: contents })
    [2.27111]
    [3.208800]
    } else {
    unreachable!()
  • edit in libpijul/src/working_copy/memory.rs at line 308
    [3.208814][3.208814:208865]()
    _ => panic!("not a file: {:?}", file),
  • edit in libpijul/src/working_copy/memory.rs at line 309
    [3.208875]
    [3.208875]
    std::mem::drop(m);
    let contents = Arc::new(Mutex::new(Vec::new()));
    let last_modified = SystemTime::now();
    self.add_inode(
    file,
    Inode::File {
    meta: InodeMetadata::new(0, false),
    contents: contents.clone(),
    last_modified,
    },
    );
    Ok(Writer { w: contents })