| author | |
| committer | |
| log | f91a8cd65409195aa7bbe74edca1e47f928092a3 |
| tree | f2cbdfe44fb34752ebb5014351755c063f9a13ad |
| parent | 73e6c5a36317d186c098ef23929b70a878cc09d3 |
| signature | Signed by SSH key SHA256:52mNGHRsVFBDED9IAX5pe+LRWUefqTbxEReunq21QvU |
sb_library_recycle_bin lists the bin's sections, Deleted Pages among them,
and sb_library_delete moves a section or group into it as OneNote 2010
deletes one. Pages leave the bin through sb_library_move_page, keeping their
identity and content, and the bin gains no placeholder page when its last one
goes; sections leave through sb_library_place.
Refs #133
Assisted-by: claude-opus-5.54 files changed, 151 insertions(+), 5 deletions(-)
crates/mobile/include/snowbound.h+2| ... | @@ -73,6 +73,8 @@ char *sb_library_new_section(const Library *library, const char *folder, const c | ... | @@ -73,6 +73,8 @@ char *sb_library_new_section(const Library *library, const char *folder, const c |
| 73 | char *sb_library_move_page(const Library *library, const char *from, const char *id, const char *to, const char *before, | 73 | char *sb_library_move_page(const Library *library, const char *from, const char *id, const char *to, const char *before, |
| 74 | uint32_t level, const char *discard, const char *author, const char *date, const char *time); | 74 | uint32_t level, const char *discard, const char *author, const char *date, const char *time); |
| 75 | char *sb_library_place(const Library *library, const char *path, const char *folder, const char *paths); | 75 | char *sb_library_place(const Library *library, const char *path, const char *folder, const char *paths); |
| 76 | char *sb_library_recycle_bin(const Library *library); | ||
| 77 | bool sb_library_delete(const Library *library, const char *path); | ||
| 76 | char *sb_search(const Library *const *libraries, size_t count, const char *section, const char *query); | 78 | char *sb_search(const Library *const *libraries, size_t count, const char *section, const char *query); |
| 77 | char *sb_library_tagged(const Library *library); | 79 | char *sb_library_tagged(const Library *library); |
| 78 | bool sb_library_unlock(const Library *library, const char *path, const char *password); | 80 | bool sb_library_unlock(const Library *library, const char *path, const char *password); |
crates/mobile/src/library.rs+54-4| ... | @@ -9,7 +9,7 @@ use notebook::{ | ... | @@ -9,7 +9,7 @@ use notebook::{ |
| 9 | discover::{Folder, Reason, SectionState}, | 9 | discover::{Folder, Reason, SectionState}, |
| 10 | live::{self, Hello, Reach, share::Guest}, | 10 | live::{self, Hello, Reach, share::Guest}, |
| 11 | provider::Documents, | 11 | provider::Documents, |
| 12 | session::{self, Background, Event, Known, Notebook, SyncStatus}, | 12 | session::{self, Background, Event, Known, Notebook, RECYCLE_BIN, SyncStatus}, |
| 13 | smb::{Client, Credentials}, | 13 | smb::{Client, Credentials}, |
| 14 | }; | 14 | }; |
| 15 | use onestore::{ | 15 | use onestore::{ |
| ... | @@ -384,7 +384,7 @@ fn tabs(folder: &Folder, unlocked: &HashMap<String, Key>, tabs: &mut Vec<Tab>) { | ... | @@ -384,7 +384,7 @@ fn tabs(folder: &Folder, unlocked: &HashMap<String, Key>, tabs: &mut Vec<Tab>) { |
| 384 | }); | 384 | }); |
| 385 | } | 385 | } |
| 386 | for group in &folder.groups { | 386 | for group in &folder.groups { |
| 387 | if !group.path.ends_with("OneNote_RecycleBin") { | 387 | if !group.path.ends_with(RECYCLE_BIN) { |
| 388 | self::tabs(group, unlocked, tabs); | 388 | self::tabs(group, unlocked, tabs); |
| 389 | } | 389 | } |
| 390 | } | 390 | } |
| ... | @@ -712,6 +712,36 @@ impl Library { | ... | @@ -712,6 +712,36 @@ impl Library { |
| 712 | } | 712 | } |
| 713 | } | 713 | } |
| 714 | 714 | ||
| 715 | /// The sections of the notebook's recycle bin, Deleted Pages among them, as `tabs` lists | ||
| 716 | /// sections; none for a lone section. | ||
| 717 | pub(crate) fn recycle_bin(&self) -> Result<Vec<Tab>> { | ||
| 718 | if matches!(self.place, Place::File(_) | Place::Document(..)) { | ||
| 719 | return Ok(Vec::new()); | ||
| 720 | } | ||
| 721 | self.with_notebook(false, |notebook| { | ||
| 722 | notebook.refresh()?; | ||
| 723 | let mut binned = Vec::new(); | ||
| 724 | let catalog = notebook.catalog(); | ||
| 725 | if let Some(bin) = catalog | ||
| 726 | .groups | ||
| 727 | .iter() | ||
| 728 | .find(|group| group.path == RECYCLE_BIN) | ||
| 729 | { | ||
| 730 | tabs(bin, &self.unlocked(), &mut binned); | ||
| 731 | } | ||
| 732 | Ok(binned) | ||
| 733 | }) | ||
| 734 | } | ||
| 735 | |||
| 736 | /// Moves the section or group at catalog `path` into the recycle bin, as OneNote 2010 | ||
| 737 | /// deletes one. | ||
| 738 | pub(crate) fn delete(&self, path: &str) -> Result<()> { | ||
| 739 | self.with_notebook(true, |notebook| { | ||
| 740 | notebook.refresh()?; | ||
| 741 | Ok(notebook.delete(path)?) | ||
| 742 | }) | ||
| 743 | } | ||
| 744 | |||
| 715 | /// The section at catalog `path`, through a replica in the cache, following Work | 745 | /// The section at catalog `path`, through a replica in the cache, following Work |
| 716 | /// Offline. The background may hold the replica for a step, which takes a network round | 746 | /// Offline. The background may hold the replica for a step, which takes a network round |
| 717 | /// trip, so a busy replica is tried again for a while. | 747 | /// trip, so a busy replica is tried again for a while. |
| ... | @@ -1492,7 +1522,8 @@ impl Library { | ... | @@ -1492,7 +1522,8 @@ impl Library { |
| 1492 | let retired = self.with_section(from, |section| { | 1522 | let retired = self.with_section(from, |section| { |
| 1493 | let mut ops = vec![Op::Section(SectionOp::Delete(vec![space]))]; | 1523 | let mut ops = vec![Op::Section(SectionOp::Delete(vec![space]))]; |
| 1494 | let added = match section.pages()?.as_slice() { | 1524 | let added = match section.pages()?.as_slice() { |
| 1495 | [(only, ..)] if *only == space => { | 1525 | // The recycle bin keeps no placeholder page. |
| 1526 | [(only, ..)] if *only == space && !from.starts_with(&format!("{RECYCLE_BIN}/")) => { | ||
| 1496 | let fresh = dated(author, date, time)?; | 1527 | let fresh = dated(author, date, time)?; |
| 1497 | let added = fresh.space(); | 1528 | let added = fresh.space(); |
| 1498 | ops.push(Op::Section(SectionOp::Create(fresh))); | 1529 | ops.push(Op::Section(SectionOp::Create(fresh))); |
| ... | @@ -2052,6 +2083,25 @@ pub unsafe extern "C" fn sb_library_move_page( | ... | @@ -2052,6 +2083,25 @@ pub unsafe extern "C" fn sb_library_move_page( |
| 2052 | })()) | 2083 | })()) |
| 2053 | } | 2084 | } |
| 2054 | 2085 | ||
| 2086 | /// The sections of the notebook's recycle bin as JSON, as `sb_library_sections` lists them: | ||
| 2087 | /// Deleted Pages, `OneNote_RecycleBin/OneNote_DeletedPages.one`, and each deleted section. | ||
| 2088 | /// Pages leave it through `sb_library_move_page`, sections through `sb_library_place`. Reads | ||
| 2089 | /// the notebook, so call it off the main thread. | ||
| 2090 | #[unsafe(no_mangle)] | ||
| 2091 | pub extern "C" fn sb_library_recycle_bin(library: &Library) -> *mut c_char { | ||
| 2092 | json(library.recycle_bin()) | ||
| 2093 | } | ||
| 2094 | |||
| 2095 | /// Moves the section or group at catalog `path` into the notebook's recycle bin; false where | ||
| 2096 | /// it can't. Writes to the notebook, so call it off the main thread. | ||
| 2097 | /// | ||
| 2098 | /// # Safety | ||
| 2099 | /// `path` is NUL-terminated UTF-8. | ||
| 2100 | #[unsafe(no_mangle)] | ||
| 2101 | pub unsafe extern "C" fn sb_library_delete(library: &Library, path: *const c_char) -> bool { | ||
| 2102 | report(library.delete(&string(path))).is_some() | ||
| 2103 | } | ||
| 2104 | |||
| 2055 | /// Puts the section or group at catalog `path` into the group at catalog path `folder` ("" | 2105 | /// Puts the section or group at catalog `path` into the group at catalog path `folder` ("" |
| 2056 | /// for the notebook's top), moving it unless it is there, then orders `folder` as `paths`, a | 2106 | /// for the notebook's top), moving it unless it is there, then orders `folder` as `paths`, a |
| 2057 | /// JSON array of catalog paths as they are named after the move; entries left out follow | 2107 | /// JSON array of catalog paths as they are named after the move; entries left out follow |
| ... | @@ -2326,7 +2376,7 @@ pub unsafe extern "C" fn sb_share_list(share: &Share, path: *const c_char) -> *m | ... | @@ -2326,7 +2376,7 @@ pub unsafe extern "C" fn sb_share_list(share: &Share, path: *const c_char) -> *m |
| 2326 | .is_some_and(|extension| extension.eq_ignore_ascii_case(wanted)) | 2376 | .is_some_and(|extension| extension.eq_ignore_ascii_case(wanted)) |
| 2327 | }; | 2377 | }; |
| 2328 | // Hidden and system folders, OneNote's recycle bin among them, stay out. | 2378 | // Hidden and system folders, OneNote's recycle bin among them, stay out. |
| 2329 | let shown = |name: &str| !name.starts_with('.') && name != "OneNote_RecycleBin"; | 2379 | let shown = |name: &str| !name.starts_with('.') && name != RECYCLE_BIN; |
| 2330 | let mut listing = Listing { | 2380 | let mut listing = Listing { |
| 2331 | notebook: entries | 2381 | notebook: entries |
| 2332 | .iter() | 2382 | .iter() |
crates/mobile/src/tests.rs+93| ... | @@ -525,6 +525,99 @@ fn a_new_page_and_subpage_list_after_their_parent_and_delete_to_the_recycle_bin( | ... | @@ -525,6 +525,99 @@ fn a_new_page_and_subpage_list_after_their_parent_and_delete_to_the_recycle_bin( |
| 525 | ); | 525 | ); |
| 526 | } | 526 | } |
| 527 | 527 | ||
| 528 | /// A page and a section deleted on iOS list in the recycle bin and leave it for places the | ||
| 529 | /// reader picks: the page for another section, keeping its identity and content, and the | ||
| 530 | /// section for a group; the files hold both on a cold reopen. | ||
| 531 | #[test] | ||
| 532 | fn deleted_pages_and_sections_restore_from_the_recycle_bin_to_where_they_are_put() { | ||
| 533 | const DELETED: &str = "OneNote_RecycleBin/OneNote_DeletedPages.one"; | ||
| 534 | const TITLE: &str = "Image role background=false, printout=false"; | ||
| 535 | let date = ["Friday, October 16, 2026", "9:00 AM"]; | ||
| 536 | let (directory, root, library, features) = notebook_open("Features.one", false); | ||
| 537 | let deleted = space(&features, TITLE); | ||
| 538 | let page = features.shared.section.page(deleted).unwrap(); | ||
| 539 | let text = canvas::search::page_text(&page); | ||
| 540 | assert!(text.contains("Foreground role control")); | ||
| 541 | features.delete_page(deleted, date[0], date[1]).unwrap(); | ||
| 542 | drop(features); | ||
| 543 | library.delete("Empty.one").unwrap(); | ||
| 544 | let binned: Vec<String> = (library.recycle_bin().unwrap().into_iter()) | ||
| 545 | .map(|tab| tab.path) | ||
| 546 | .collect(); | ||
| 547 | assert_eq!(binned, [DELETED, "OneNote_RecycleBin/Empty.one"]); | ||
| 548 | assert!( | ||
| 549 | library | ||
| 550 | .tabs() | ||
| 551 | .unwrap() | ||
| 552 | .iter() | ||
| 553 | .all(|tab| tab.path != "Empty.one") | ||
| 554 | ); | ||
| 555 | |||
| 556 | let bin = open(&library, DELETED); | ||
| 557 | let recycled = space(&bin, TITLE); | ||
| 558 | drop(bin); | ||
| 559 | let restored = library | ||
| 560 | .move_page( | ||
| 561 | DELETED, | ||
| 562 | recycled, | ||
| 563 | "Group A/Duplicate.one", | ||
| 564 | None, | ||
| 565 | 1, | ||
| 566 | None, | ||
| 567 | "Clover Test", | ||
| 568 | date, | ||
| 569 | ) | ||
| 570 | .unwrap(); | ||
| 571 | assert_eq!(restored.added, None, "the bin gains no placeholder page"); | ||
| 572 | assert_eq!(restored.copied, None); | ||
| 573 | assert!( | ||
| 574 | open(&library, DELETED) | ||
| 575 | .shared | ||
| 576 | .section | ||
| 577 | .pages() | ||
| 578 | .unwrap() | ||
| 579 | .is_empty() | ||
| 580 | ); | ||
| 581 | assert_eq!( | ||
| 582 | library | ||
| 583 | .place("OneNote_RecycleBin/Empty.one", "Group B", &[]) | ||
| 584 | .unwrap(), | ||
| 585 | "Group B/Empty.one" | ||
| 586 | ); | ||
| 587 | library.close(Duration::from_secs(20)).unwrap(); | ||
| 588 | drop(library); | ||
| 589 | |||
| 590 | let cold = Library::open(&root, &directory.path().join("cold"), true).unwrap(); | ||
| 591 | let paths: Vec<String> = cold | ||
| 592 | .tabs() | ||
| 593 | .unwrap() | ||
| 594 | .into_iter() | ||
| 595 | .map(|tab| tab.path) | ||
| 596 | .collect(); | ||
| 597 | assert!(paths.contains(&"Group B/Empty.one".to_owned())); | ||
| 598 | let listed = take_json(library::sb_library_recycle_bin(&cold)); | ||
| 599 | assert_eq!(listed[0]["path"], DELETED); | ||
| 600 | assert_eq!(listed.as_array().unwrap().len(), 1); | ||
| 601 | let arrived = restored.page.parse().unwrap(); | ||
| 602 | let file = root.join("Group A/Duplicate.one"); | ||
| 603 | assert_eq!(stored_text(&file, arrived), text); | ||
| 604 | let stored = notebook::session::stored_pages(&std::fs::read(&file).unwrap()).unwrap(); | ||
| 605 | let back = stored | ||
| 606 | .iter() | ||
| 607 | .find(|stored| stored.space == arrived) | ||
| 608 | .unwrap(); | ||
| 609 | assert_eq!(back.page.title, TITLE); | ||
| 610 | assert_eq!( | ||
| 611 | back.page.identity, page.identity, | ||
| 612 | "a restored page keeps its identity" | ||
| 613 | ); | ||
| 614 | assert!( | ||
| 615 | notebook::session::stored_pages(&std::fs::read(root.join(DELETED)).unwrap()) | ||
| 616 | .unwrap() | ||
| 617 | .is_empty() | ||
| 618 | ); | ||
| 619 | } | ||
| 620 | |||
| 528 | #[test] | 621 | #[test] |
| 529 | fn deleting_a_lone_section_page_still_creates_its_replacement_without_a_bin() { | 622 | fn deleting_a_lone_section_page_still_creates_its_replacement_without_a_bin() { |
| 530 | let directory = tempfile::tempdir().unwrap(); | 623 | let directory = tempfile::tempdir().unwrap(); |
crates/notebook/src/session.rs+2-1| ... | @@ -475,7 +475,8 @@ pub(crate) const LIMITS: discover::Limits = discover::Limits { | ... | @@ -475,7 +475,8 @@ pub(crate) const LIMITS: discover::Limits = discover::Limits { |
| 475 | }; | 475 | }; |
| 476 | 476 | ||
| 477 | const TOC: &str = "Open Notebook.onetoc2"; | 477 | const TOC: &str = "Open Notebook.onetoc2"; |
| 478 | const RECYCLE_BIN: &str = "OneNote_RecycleBin"; | 478 | /// The recycle bin's folder, a section group of the notebook's. |
| 479 | pub const RECYCLE_BIN: &str = "OneNote_RecycleBin"; | ||
| 479 | /// How long OneNote 2010 keeps what its recycle bin holds, its `DaysToKeepRecycledItems`. | 480 | /// How long OneNote 2010 keeps what its recycle bin holds, its `DaysToKeepRecycledItems`. |
| 480 | pub const RECYCLE_DAYS: u32 = 60; | 481 | pub const RECYCLE_DAYS: u32 = 60; |
| 481 | 482 |