Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix up diverging structure in bookmark trees #19

Merged
merged 15 commits into from
Jan 30, 2019
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ pub enum ErrorKind {
MergeConflict,
UnmergedLocalItems,
UnmergedRemoteItems,
GenerateGuid,
}

impl fmt::Display for ErrorKind {
Expand Down Expand Up @@ -83,6 +84,9 @@ impl fmt::Display for ErrorKind {
},
ErrorKind::UnmergedRemoteItems => {
write!(f, "Merged tree doesn't mention all items from remote tree")
},
ErrorKind::GenerateGuid => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little confused by this because I can't really see how it will be used in real code, but I note that the places lib will panic if it can't generate a GUID, so it doesn't have any error similar to this. OTOH though, at least in the default trait below, this error is actually used as "I decline to create a new GUID" - so I'm not sure if this is intended for "can't" or "won't".

I guess that I'm suggesting we add a comment below...

write!(f, "Failed to generate GUID")
}
}
}
Expand Down
12 changes: 11 additions & 1 deletion src/guid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,15 @@ enum Repr {
/// The Places root GUID, used to root all items in a bookmark tree.
pub const ROOT_GUID: Guid = Guid(Repr::Fast(*b"root________"));

/// The "Other Bookmarks" GUID, used to hold items without a parent.
pub const UNFILED_GUID: Guid = Guid(Repr::Fast(*b"unfiled_____"));

/// The syncable Places roots. All synced items should descend from these
/// roots.
pub const USER_CONTENT_ROOTS: [Guid; 4] = [
Guid(Repr::Fast(*b"toolbar_____")),
Guid(Repr::Fast(*b"menu________")),
Guid(Repr::Fast(*b"unfiled_____")),
UNFILED_GUID,
Guid(Repr::Fast(*b"mobile______")),
];

Expand Down Expand Up @@ -117,6 +120,13 @@ impl Guid {
}
}

pub fn valid(&self) -> bool {
match self.0 {
Repr::Fast(_) => true,
Repr::Slow(_) => false,
}
}

/// Equivalent to `PlacesUtils.isValidGuid`.
#[inline]
fn is_valid<T: Copy + IntoByte>(bytes: &[T]) -> bool {
Expand Down
Loading