-
Notifications
You must be signed in to change notification settings - Fork 10
Conversation
}; | ||
let path_buf = CanonicalPathBuf::canonicalize(&file_path).unwrap(); | ||
let update = actual | ||
.update_one(path_buf.clone(), old_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now I'm curious what happens if a user of the lib passes wrong old_id
...
let update = actual | ||
.update_one(path_buf.clone(), old_id) | ||
.expect("Should update one resource correctly"); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this current scenario, the update should be empty (nothing changed).
Probably reasoning with paths instead of files would be better here:
- If we remove a file with id
id1
and pathpath1
then the update isdeleted(id1)
- If we modify a file by path
path1
so it's new id isid2
then the update isdeleted(id1), added(id2)
- If we rename/move a file with
id1
frompath1
topath2
then the update isdeleted(id1), added(id1)
Please, double-check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Notion of a "file" is confusing here because it is combination of path and content, but index works with paths and contents separately. A "resource" is an identified content, a "path" it's current location.
@@ -904,4 +904,23 @@ mod tests { | |||
assert!(new2 > old2); | |||
assert!(new2 > new1); | |||
} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Idea for a test case:
- Build the index of folder with paths e.g.
root/A
androot/B
. - Create file by path
root/C
. - Call
update_one("root/C", id)
.
Two cases:
a)id
matches the content of new resource
b)id
does not - What should be the result?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, alright. Should it replace the current one or is it a new unittest?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New one
Should we create new struct for the error So, if the caller doesn't have information that the resource changed, it's a mistake to call this method. But if the resource was changed indeed (timestamp must be changed, too) and new content has same size and same CRC-32 hash — then it's a collision indeed. We can also split single error into two different errors for clarity, depending on was the timestamp changed or not. |
Superseded by #72 |
update_all
andupdate_one
are consistent #41