FileSet: implement rename

andybalholm
Apr 15, 2023, 4:25 PM
WQACY5X6MSK7NXFXKV5LSU77RU3UHEHK234GFJ4QUQCZZ23FMHKAC

Dependencies

  • [2] FIIUZR4L Include file content
  • [3] ZGFCBIPX FileSet: no error for remove_path
  • [*] ATRA7XTT RIIR: factor out Repository struct

Change contents

  • edit in src/repo.rs at line 306
    [2.3430][2.3430:3472]()
    RenameNotImplemented(String, String),
  • edit in src/repo.rs at line 315
    [2.3799][2.3799:3946]()
    FileSetError::RenameNotImplemented(old, new) => {
    write!(f, "not implemented: rename({}, {})", old, new)
    }
  • replacement in src/repo.rs at line 349
    [2.4996][2.4996:5113]()
    Err(FileSetError::RenameNotImplemented(
    old.to_string(),
    new.to_string(),
    ))
    [2.4996]
    [2.5113]
    let mut with_slash = old.to_owned();
    with_slash.push_str("/");
    let mut files = self.files.lock().unwrap();
    for f in files.iter_mut() {
    if f.name == old {
    f.name = new.to_owned();
    } else if f.name.starts_with(&with_slash) {
    let (_, remainder) = f.name.split_at(old.len());
    let mut new_name = new.to_owned();
    new_name.push_str(remainder);
    f.name = new_name;
    }
    }
    Ok(())