mirror of
https://github.com/narrrl/proton-drive-linux.git
synced 2026-11-04 16:56:59 +01:00
fix(core,fuse): a node written under its stand-in after landing updates its landed row
This commit is contained in:
1 parent
9c93860cd8
commit
dbc4d9a8c5
4 files changed
+66
-30
No files matched your search
@@ -900,8 +900,25 @@ fn adopt_children_tx(tx: &Transaction<'_>, uid: &str, lid: i64) -> Result<()> {
|
||||
}
|
||||
|
||||
fn upsert_node_tx(tx: &Transaction<'_>, node: &Node) -> Result<()> {
|
||||
let json = serde_json::to_string(node)?;
|
||||
let uid = node.uid.to_string();
|
||||
// A node written under its stand-in after it landed is its row, which has
|
||||
// the uid Drive gave it by now: written under the stand-in, it would bring
|
||||
// the placeholder row back beside it.
|
||||
if let Some(lid) = local_lid(&uid) {
|
||||
let landed: Option<String> = tx
|
||||
.query_row(
|
||||
"SELECT uid FROM nodes WHERE lid = ?1 AND uid IS NOT ?2",
|
||||
params![lid, uid],
|
||||
|row| row.get(0),
|
||||
)
|
||||
.optional()?;
|
||||
if let Some(real) = landed.as_deref().and_then(parse_node_uid) {
|
||||
let mut node = node.clone();
|
||||
node.uid = real;
|
||||
return upsert_node_tx(tx, &node);
|
||||
}
|
||||
}
|
||||
let json = serde_json::to_string(node)?;
|
||||
let parent_uid = node.parent_uid.as_ref().map(|u| u.to_string());
|
||||
|
||||
let prior: Option<PriorRow> = tx
|
||||
|
||||
@@ -3964,6 +3964,43 @@ fn a_landed_folder_rewrites_no_row_or_op_below_it() {
|
||||
);
|
||||
}
|
||||
|
||||
/// A node the mount still holds under its stand-in, written after it landed,
|
||||
/// updates the landed row: written under the stand-in, it brought the
|
||||
/// placeholder row back beside it.
|
||||
#[test]
|
||||
fn a_stand_in_written_after_landing_updates_the_landed_row() {
|
||||
let db = Db::open_in_memory().unwrap();
|
||||
db.upsert_node(&folder("root", None, "My Files")).unwrap();
|
||||
let lid = db
|
||||
.add_local_row(&uid("root").to_string(), "a.txt", false, 1)
|
||||
.unwrap();
|
||||
let local = local_uid(lid);
|
||||
let mut node = file("x", "root", "a.txt", 3);
|
||||
node.uid = NodeUid::new(VolumeId::from("local"), LinkId::from(lid.to_string()));
|
||||
db.upsert_node(&node).unwrap();
|
||||
db.land_placeholder_row(&local, &uid("a").to_string())
|
||||
.unwrap();
|
||||
|
||||
node.name = "b.txt".into();
|
||||
db.upsert_node(&node).unwrap();
|
||||
|
||||
let rows: Vec<(i64, String, String)> = {
|
||||
let conn = db.conn.lock();
|
||||
let mut stmt = conn
|
||||
.prepare("SELECT lid, uid, name FROM nodes WHERE uid != ?1")
|
||||
.unwrap();
|
||||
stmt.query_map([uid("root").to_string()], |r| {
|
||||
Ok((r.get(0)?, r.get(1)?, r.get(2)?))
|
||||
})
|
||||
.unwrap()
|
||||
.collect::<rusqlite::Result<_>>()
|
||||
.unwrap()
|
||||
};
|
||||
assert_eq!(rows, [(lid, uid("a").to_string(), "b.txt".to_string())]);
|
||||
let landed = db.node_by_uid(&uid("a").to_string()).unwrap().unwrap();
|
||||
assert_eq!((landed.uid, landed.name), (uid("a"), "b.txt".to_string()));
|
||||
}
|
||||
|
||||
/// A create queued inside a folder made here is sent under the folder's real
|
||||
/// uid once it lands. Landing where it was sent is no move.
|
||||
#[test]
|
||||
|
||||
Reference in new issue
Block a user