| author | |
| committer | |
| log | 2f91a95387b710cc973f6ae8facbecca45b8a499 |
| tree | 689c74794991eb8bc8fd9fd57f9004db9f808ae1 |
| parent | e402bcaea68f6837c079a7176a870a9d6dbdfb65 |
| signature | Signed by SSH key SHA256:52mNGHRsVFBDED9IAX5pe+LRWUefqTbxEReunq21QvU |
Review of the Recycle Bin: a notebook whose last section was deleted lost its
Notebook Recycle Bin item, which is now kept for every open notebook folder.
The bin is pruned of what it has held past 60 days when a notebook opens, as
OneNote and the desktop do, so its footer holds. A section deleted with edits
waiting is listed again at once, so the background publishes them to the
binned file. On a share the bin is listed with the notebook, so Deleted Pages
opens there, as it would not when the bin was made after the last listing; a
lab test restores a page from a Samba share's bin while offline and finds it in
place on a cold reopen once online. Deleted Pages that can't be opened says so rather than that the
bin is empty, and Restore To greys out a folder already holding a section file
of the same name, letters' case aside, and says why.
- Notebook Recycle Bin stays in a notebook's menu after its last section is deleted.
- The Recycle Bin is emptied of what it has held for 60 days when the notebook opens, as OneNote does.
- The Recycle Bin says when it can't be opened instead of showing it empty.
- The Recycle Bin of a notebook on a server opens its deleted pages.
- Restore To greys out a folder holding a section of the same name, saying why, whatever the letters' case.
- Each Restore button names what it restores to VoiceOver, and notes stay up while VoiceOver runs.
Refs #133
Assisted-by: claude-opus-5.56 files changed, 227 insertions(+), 25 deletions(-)
apps/ios/Snowbound/Notebooks.swift+7-1| ... | @@ -262,6 +262,11 @@ final class Notebook { | ... | @@ -262,6 +262,11 @@ final class Notebook { |
| 262 | self.problem = library == nil ? (problem ?? "The notebook can’t be read.") : nil | 262 | self.problem = library == nil ? (problem ?? "The notebook can’t be read.") : nil |
| 263 | follow() | 263 | follow() |
| 264 | reload(done: done) | 264 | reload(done: done) |
| 265 | // As OneNote prunes the recycle bin after opening. | ||
| 266 | if let library { | ||
| 267 | let pointer = Int(bitPattern: library) | ||
| 268 | background({ sb_library_purge_recycle_bin(OpaquePointer(bitPattern: pointer)) }) { _ in } | ||
| 269 | } | ||
| 265 | } | 270 | } |
| 266 | } | 271 | } |
| 267 | 272 | ||
| ... | @@ -785,7 +790,8 @@ final class Section { | ... | @@ -785,7 +790,8 @@ final class Section { |
| 785 | done() | 790 | done() |
| 786 | if recycled > 0, let window { | 791 | if recycled > 0, let window { |
| 787 | let title = recycled == 1 ? "Page Moved to Recycle Bin" : "\(recycled) Pages Moved to Recycle Bin" | 792 | let title = recycled == 1 ? "Page Moved to Recycle Bin" : "\(recycled) Pages Moved to Recycle Bin" |
| 788 | SyncToast.show(title, "Tap to restore", symbol: "trash", hint: "Opens the Recycle Bin", in: window) { | 793 | let detail = recycled == 1 ? "Restore it from the Recycle Bin" : "Restore them from the Recycle Bin" |
| 794 | SyncToast.show(title, detail, symbol: "trash", hint: "Opens the Recycle Bin", in: window) { | ||
| 789 | [notebook = self.notebook] in RecycleBinViewController.present(notebook, in: window) | 795 | [notebook = self.notebook] in RecycleBinViewController.present(notebook, in: window) |
| 790 | } | 796 | } |
| 791 | } | 797 | } |
apps/ios/Snowbound/Recycle.swift+40-21| ... | @@ -1,8 +1,9 @@ | ... | @@ -1,8 +1,9 @@ |
| 1 | import UIKit | 1 | import UIKit |
| 2 | 2 | ||
| 3 | extension Notebook { | 3 | extension Notebook { |
| 4 | /// Whether the notebook keeps a recycle bin: a folder does, a lone section doesn't. | 4 | /// Whether the notebook keeps a recycle bin: an open folder does, even with no sections |
| 5 | var hasRecycleBin: Bool { tabs.contains { !$0.path.isEmpty && !$0.path.hasPrefix("/") } } | 5 | /// left, and a lone section, listed by its file's path or none, doesn't. |
| 6 | var hasRecycleBin: Bool { handle != nil && !tabs.contains { $0.path.isEmpty || $0.path.hasPrefix("/") } } | ||
| 6 | } | 7 | } |
| 7 | 8 | ||
| 8 | /// OneNote's Notebook Recycle Bin: the pages and sections deleted from a notebook, each | 9 | /// OneNote's Notebook Recycle Bin: the pages and sections deleted from a notebook, each |
| ... | @@ -14,6 +15,7 @@ final class RecycleBinViewController: UITableViewController { | ... | @@ -14,6 +15,7 @@ final class RecycleBinViewController: UITableViewController { |
| 14 | /// Deleted Pages, open while the bin shows. | 15 | /// Deleted Pages, open while the bin shows. |
| 15 | private var deleted: Section? | 16 | private var deleted: Section? |
| 16 | private var sections: [Tab] = [] | 17 | private var sections: [Tab] = [] |
| 18 | private var observers: [NSObjectProtocol] = [] | ||
| 17 | 19 | ||
| 18 | /// Shows `notebook`'s bin as a sheet over the controller on top of `window`. | 20 | /// Shows `notebook`'s bin as a sheet over the controller on top of `window`. |
| 19 | static func present(_ notebook: Notebook, in window: UIWindow?) { | 21 | static func present(_ notebook: Notebook, in window: UIWindow?) { |
| ... | @@ -33,16 +35,24 @@ final class RecycleBinViewController: UITableViewController { | ... | @@ -33,16 +35,24 @@ final class RecycleBinViewController: UITableViewController { |
| 33 | 35 | ||
| 34 | required init?(coder: NSCoder) { fatalError() } | 36 | required init?(coder: NSCoder) { fatalError() } |
| 35 | 37 | ||
| 38 | deinit { observers.forEach(NotificationCenter.default.removeObserver) } | ||
| 39 | |||
| 36 | override func viewDidLoad() { | 40 | override func viewDidLoad() { |
| 37 | super.viewDidLoad() | 41 | super.viewDidLoad() |
| 38 | tableView.register(UITableViewCell.self, forCellReuseIdentifier: "binned") | 42 | tableView.register(UITableViewCell.self, forCellReuseIdentifier: "binned") |
| 39 | navigationItem.rightBarButtonItem = UIBarButtonItem( | 43 | navigationItem.rightBarButtonItem = UIBarButtonItem( |
| 40 | systemItem: .done, primaryAction: UIAction { [weak self] _ in self?.dismiss(animated: true) }) | 44 | systemItem: .done, primaryAction: UIAction { [weak self] _ in self?.dismiss(animated: true) }) |
| 41 | NotificationCenter.default.addObserver(forName: Section.changed, object: nil, queue: .main) { [weak self] note in | 45 | observers = [ |
| 42 | if let self, note.object as AnyObject? === deleted { show() } | 46 | NotificationCenter.default.addObserver(forName: Section.changed, object: nil, queue: .main) { [weak self] note in |
| 43 | } | 47 | if let self, note.object as AnyObject? === deleted { show() } |
| 44 | NotificationCenter.default.addObserver(forName: Notebook.listed, object: notebook, queue: .main) { [weak self] _ in | 48 | }, |
| 45 | self?.reload() | 49 | NotificationCenter.default.addObserver(forName: Notebook.listed, object: notebook, queue: .main) { |
| 50 | [weak self] _ in self?.reload() | ||
| 51 | }, | ||
| 52 | ] | ||
| 53 | // Each row's Restore button takes its size as the row is made. | ||
| 54 | registerForTraitChanges([UITraitPreferredContentSizeCategory.self]) { (self: Self, _) in | ||
| 55 | self.tableView.reloadData() | ||
| 46 | } | 56 | } |
| 47 | var loading = UIContentUnavailableConfiguration.loading() | 57 | var loading = UIContentUnavailableConfiguration.loading() |
| 48 | loading.text = "Opening…" | 58 | loading.text = "Opening…" |
| ... | @@ -53,26 +63,29 @@ final class RecycleBinViewController: UITableViewController { | ... | @@ -53,26 +63,29 @@ final class RecycleBinViewController: UITableViewController { |
| 53 | private var pages: [Row] { deleted?.rows ?? [] } | 63 | private var pages: [Row] { deleted?.rows ?? [] } |
| 54 | 64 | ||
| 55 | private func reload() { | 65 | private func reload() { |
| 56 | guard let library = notebook.handle else { return } | 66 | guard let library = notebook.handle else { return failed(notebook.problem) } |
| 57 | let pointer = Int(bitPattern: library) | 67 | let pointer = Int(bitPattern: library) |
| 58 | background({ decode([Tab].self, sb_library_recycle_bin(OpaquePointer(bitPattern: pointer))) }) { [weak self] tabs in | 68 | background({ decode([Tab].self, sb_library_recycle_bin(OpaquePointer(bitPattern: pointer))) }) { [weak self] tabs in |
| 59 | guard let self else { return } | 69 | guard let self else { return } |
| 60 | guard let tabs else { | 70 | guard let tabs else { return failed(nil) } |
| 61 | var failed = UIContentUnavailableConfiguration.empty() | ||
| 62 | failed.text = "Can’t Open Recycle Bin" | ||
| 63 | failed.secondaryText = "Check that the notebook can be reached, then try again." | ||
| 64 | contentUnavailableConfiguration = failed | ||
| 65 | return | ||
| 66 | } | ||
| 67 | sections = tabs.filter { $0.path != Self.deletedPages } | 71 | sections = tabs.filter { $0.path != Self.deletedPages } |
| 68 | guard deleted == nil, let tab = tabs.first(where: { $0.path == Self.deletedPages }) else { return show() } | 72 | guard deleted == nil, let tab = tabs.first(where: { $0.path == Self.deletedPages }) else { return show() } |
| 69 | Section.open(tab, of: notebook) { [weak self] section, _ in | 73 | Section.open(tab, of: notebook) { [weak self] section, problem in |
| 74 | guard let section else { return self?.failed(problem) ?? () } | ||
| 70 | self?.deleted = section | 75 | self?.deleted = section |
| 71 | self?.show() | 76 | self?.show() |
| 72 | } | 77 | } |
| 73 | } | 78 | } |
| 74 | } | 79 | } |
| 75 | 80 | ||
| 81 | /// Says the bin can't be read, rather than that it is empty. | ||
| 82 | private func failed(_ problem: String?) { | ||
| 83 | var failed = UIContentUnavailableConfiguration.empty() | ||
| 84 | failed.text = "Can’t Open Recycle Bin" | ||
| 85 | failed.secondaryText = problem ?? "Check that the notebook can be reached, then try again." | ||
| 86 | contentUnavailableConfiguration = failed | ||
| 87 | } | ||
| 88 | |||
| 76 | private func show() { | 89 | private func show() { |
| 77 | tableView.reloadData() | 90 | tableView.reloadData() |
| 78 | var empty = UIContentUnavailableConfiguration.empty() | 91 | var empty = UIContentUnavailableConfiguration.empty() |
| ... | @@ -119,6 +132,7 @@ final class RecycleBinViewController: UITableViewController { | ... | @@ -119,6 +132,7 @@ final class RecycleBinViewController: UITableViewController { |
| 119 | let button = UIButton(configuration: restore) | 132 | let button = UIButton(configuration: restore) |
| 120 | button.menu = menu(at: indexPath) | 133 | button.menu = menu(at: indexPath) |
| 121 | button.showsMenuAsPrimaryAction = true | 134 | button.showsMenuAsPrimaryAction = true |
| 135 | button.accessibilityLabel = "Restore \(content.text ?? "")" | ||
| 122 | button.sizeToFit() | 136 | button.sizeToFit() |
| 123 | cell.accessoryView = button | 137 | cell.accessoryView = button |
| 124 | return cell | 138 | return cell |
| ... | @@ -142,16 +156,21 @@ final class RecycleBinViewController: UITableViewController { | ... | @@ -142,16 +156,21 @@ final class RecycleBinViewController: UITableViewController { |
| 142 | Arranging.move(page: page, of: notebook, from: Self.deletedPages, to: tab.path) | 156 | Arranging.move(page: page, of: notebook, from: Self.deletedPages, to: tab.path) |
| 143 | } | 157 | } |
| 144 | } | 158 | } |
| 145 | return UIMenu(title: "Restore To", children: choices) | 159 | let none = UIAction(title: "No Sections", subtitle: "Add or restore a section first", attributes: .disabled) { _ in } |
| 160 | return UIMenu(title: "Restore To", children: choices.isEmpty ? [none] : choices) | ||
| 146 | } | 161 | } |
| 147 | let path = sections[indexPath.row].path | 162 | let path = sections[indexPath.row].path |
| 148 | let file = path.split(separator: "/").last.map(String.init) ?? path | 163 | let file = path.split(separator: "/").last.map(String.init) ?? path |
| 149 | let choices = ([""] + notebook.groups).map { folder in | 164 | let choices = ([""] + notebook.groups).map { folder in |
| 150 | // A section of the same file name there would refuse it. | 165 | // A section of the same file name there would refuse it, as the file systems |
| 151 | let taken = notebook.entries(in: folder).contains { $0.split(separator: "/").last.map(String.init) == file } | 166 | // notebooks live on ignore case. |
| 152 | return UIAction(title: folder.isEmpty ? notebook.name : place(folder), attributes: taken ? .disabled : []) { | 167 | let taken = notebook.entries(in: folder).contains { |
| 153 | [notebook] _ in Arranging.place(path, of: notebook, in: folder) | 168 | ($0.split(separator: "/").last.map(String.init) ?? $0).caseInsensitiveCompare(file) == .orderedSame |
| 154 | } | 169 | } |
| 170 | return UIAction( | ||
| 171 | title: folder.isEmpty ? notebook.name : place(folder), | ||
| 172 | subtitle: taken ? "A section with this name is already here" : nil, attributes: taken ? .disabled : [] | ||
| 173 | ) { [notebook] _ in Arranging.place(path, of: notebook, in: folder) } | ||
| 155 | } | 174 | } |
| 156 | return UIMenu(title: "Restore To", children: choices) | 175 | return UIMenu(title: "Restore To", children: choices) |
| 157 | } | 176 | } |
apps/ios/Snowbound/Sync.swift+8-1| ... | @@ -172,7 +172,14 @@ enum SyncToast { | ... | @@ -172,7 +172,14 @@ enum SyncToast { |
| 172 | ]) | 172 | ]) |
| 173 | UIView.animate(withDuration: 0.3) { toast.alpha = 1 } | 173 | UIView.animate(withDuration: 0.3) { toast.alpha = 1 } |
| 174 | UIAccessibility.post(notification: .announcement, argument: "\(title). \(detail)") | 174 | UIAccessibility.post(notification: .announcement, argument: "\(title). \(detail)") |
| 175 | DispatchQueue.main.asyncAfter(deadline: .now() + 6, execute: dismiss) | 175 | // VoiceOver needs time to reach it, so it stays while VoiceOver runs. |
| 176 | func expire() { | ||
| 177 | DispatchQueue.main.asyncAfter(deadline: .now() + 6) { [weak toast] in | ||
| 178 | guard toast?.superview != nil else { return } | ||
| 179 | if UIAccessibility.isVoiceOverRunning { expire() } else { dismiss() } | ||
| 180 | } | ||
| 181 | } | ||
| 182 | expire() | ||
| 176 | } | 183 | } |
| 177 | } | 184 | } |
| 178 | 185 |
crates/mobile/include/snowbound.h+1| ... | @@ -74,6 +74,7 @@ char *sb_library_move_page(const Library *library, const char *from, const char | ... | @@ -74,6 +74,7 @@ char *sb_library_move_page(const Library *library, const char *from, const char |
| 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); | 76 | char *sb_library_recycle_bin(const Library *library); |
| 77 | void sb_library_purge_recycle_bin(const Library *library); | ||
| 77 | bool sb_library_delete(const Library *library, const char *path); | 78 | bool sb_library_delete(const Library *library, const char *path); |
| 78 | char *sb_search(const Library *const *libraries, size_t count, const char *section, const char *query); | 79 | char *sb_search(const Library *const *libraries, size_t count, const char *section, const char *query); |
| 79 | char *sb_library_tagged(const Library *library); | 80 | char *sb_library_tagged(const Library *library); |
crates/mobile/src/library.rs+26-2| ... | @@ -718,8 +718,9 @@ impl Library { | ... | @@ -718,8 +718,9 @@ impl Library { |
| 718 | if matches!(self.place, Place::File(_) | Place::Document(..)) { | 718 | if matches!(self.place, Place::File(_) | Place::Document(..)) { |
| 719 | return Ok(Vec::new()); | 719 | return Ok(Vec::new()); |
| 720 | } | 720 | } |
| 721 | // Listed again, a share's bin sections open by the identities the listing keeps. | ||
| 722 | self.tabs()?; | ||
| 721 | self.with_notebook(false, |notebook| { | 723 | self.with_notebook(false, |notebook| { |
| 722 | notebook.refresh()?; | ||
| 723 | let mut binned = Vec::new(); | 724 | let mut binned = Vec::new(); |
| 724 | let catalog = notebook.catalog(); | 725 | let catalog = notebook.catalog(); |
| 725 | if let Some(bin) = catalog | 726 | if let Some(bin) = catalog |
| ... | @@ -733,13 +734,28 @@ impl Library { | ... | @@ -733,13 +734,28 @@ impl Library { |
| 733 | }) | 734 | }) |
| 734 | } | 735 | } |
| 735 | 736 | ||
| 737 | /// Deletes for good what the recycle bin has held unchanged past OneNote's 60 days, as | ||
| 738 | /// OneNote 2010 prunes it after opening; a guest leaves that to its host's notebook, and a | ||
| 739 | /// share not reached is left for the next time. | ||
| 740 | pub(crate) fn purge_recycle_bin(&self) -> Result<usize> { | ||
| 741 | if matches!(self.place, Place::Hosted(_)) || self.notebook().is_none() { | ||
| 742 | return Ok(0); | ||
| 743 | } | ||
| 744 | // Time32 counts seconds from 1980; FILETIME, tenths of microseconds from 1601. | ||
| 745 | let now = (filetime() / 10_000_000).saturating_sub(11_960_006_400); | ||
| 746 | let now = u32::try_from(now).unwrap_or(u32::MAX); | ||
| 747 | self.with_notebook(true, |notebook| Ok(notebook.purge_recycle_bin(now)?)) | ||
| 748 | } | ||
| 749 | |||
| 736 | /// Moves the section or group at catalog `path` into the recycle bin, as OneNote 2010 | 750 | /// Moves the section or group at catalog `path` into the recycle bin, as OneNote 2010 |
| 737 | /// deletes one. | 751 | /// deletes one. |
| 738 | pub(crate) fn delete(&self, path: &str) -> Result<()> { | 752 | pub(crate) fn delete(&self, path: &str) -> Result<()> { |
| 739 | self.with_notebook(true, |notebook| { | 753 | self.with_notebook(true, |notebook| { |
| 740 | notebook.refresh()?; | 754 | notebook.refresh()?; |
| 741 | Ok(notebook.delete(path)?) | 755 | Ok(notebook.delete(path)?) |
| 742 | }) | 756 | })?; |
| 757 | // Listed again, the background syncs the binned sections, edits waiting among them. | ||
| 758 | self.tabs().map(drop) | ||
| 743 | } | 759 | } |
| 744 | 760 | ||
| 745 | /// The section at catalog `path`, through a replica in the cache, following Work | 761 | /// The section at catalog `path`, through a replica in the cache, following Work |
| ... | @@ -2092,6 +2108,14 @@ pub extern "C" fn sb_library_recycle_bin(library: &Library) -> *mut c_char { | ... | @@ -2092,6 +2108,14 @@ pub extern "C" fn sb_library_recycle_bin(library: &Library) -> *mut c_char { |
| 2092 | json(library.recycle_bin()) | 2108 | json(library.recycle_bin()) |
| 2093 | } | 2109 | } |
| 2094 | 2110 | ||
| 2111 | /// Deletes for good what the notebook's recycle bin has held unchanged past 60 days, as | ||
| 2112 | /// OneNote 2010 does after opening a notebook. Writes to the notebook, so call it off the main | ||
| 2113 | /// thread. | ||
| 2114 | #[unsafe(no_mangle)] | ||
| 2115 | pub extern "C" fn sb_library_purge_recycle_bin(library: &Library) { | ||
| 2116 | report(library.purge_recycle_bin()); | ||
| 2117 | } | ||
| 2118 | |||
| 2095 | /// Moves the section or group at catalog `path` into the notebook's recycle bin; false where | 2119 | /// 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. | 2120 | /// it can't. Writes to the notebook, so call it off the main thread. |
| 2097 | /// | 2121 | /// |
crates/mobile/src/tests.rs+145| ... | @@ -618,6 +618,63 @@ fn deleted_pages_and_sections_restore_from_the_recycle_bin_to_where_they_are_put | ... | @@ -618,6 +618,63 @@ fn deleted_pages_and_sections_restore_from_the_recycle_bin_to_where_they_are_put |
| 618 | ); | 618 | ); |
| 619 | } | 619 | } |
| 620 | 620 | ||
| 621 | /// A group deleted through the C surface takes its sections to the recycle bin, one with an | ||
| 622 | /// edit not yet published keeping it there; and a page leaves Deleted Pages while the bin | ||
| 623 | /// holds it open, as the iOS sheet does. | ||
| 624 | #[test] | ||
| 625 | fn a_group_with_an_unpublished_edit_goes_to_the_bin_and_an_open_bin_gives_up_its_page() { | ||
| 626 | const DELETED: &str = "OneNote_RecycleBin/OneNote_DeletedPages.one"; | ||
| 627 | let date = ["Monday, October 19, 2026", "9:00 AM"]; | ||
| 628 | let (_directory, root, library, features) = notebook_open("Features.one", true); | ||
| 629 | let duplicate = open(&library, "Group A/Duplicate.one"); | ||
| 630 | let before = duplicate.rows().unwrap().len(); | ||
| 631 | duplicate.new_page(None, date[0], date[1]).unwrap(); | ||
| 632 | duplicate.shared.section.written().unwrap(); | ||
| 633 | drop(duplicate); | ||
| 634 | let group = CString::new("Group A").unwrap(); | ||
| 635 | assert!(unsafe { library::sb_library_delete(&library, group.as_ptr()) }); | ||
| 636 | let binned = "OneNote_RecycleBin/Duplicate.one"; | ||
| 637 | let listed = take_json(library::sb_library_recycle_bin(&library)); | ||
| 638 | assert!( | ||
| 639 | listed | ||
| 640 | .as_array() | ||
| 641 | .unwrap() | ||
| 642 | .iter() | ||
| 643 | .any(|tab| tab["path"] == binned) | ||
| 644 | ); | ||
| 645 | assert!(!root.join("Group A").exists()); | ||
| 646 | sb_library_set_offline(&library, false); | ||
| 647 | sb_library_sync_now(&library); | ||
| 648 | let stored = || { | ||
| 649 | let bytes = std::fs::read(root.join(binned)).unwrap(); | ||
| 650 | notebook::session::stored_pages(&bytes).unwrap().len() | ||
| 651 | }; | ||
| 652 | assert!( | ||
| 653 | eventually(|| stored() == before + 1), | ||
| 654 | "the edit reached the binned section" | ||
| 655 | ); | ||
| 656 | |||
| 657 | let space = features.rows().unwrap()[0].id.parse().unwrap(); | ||
| 658 | features.delete_page(space, date[0], date[1]).unwrap(); | ||
| 659 | drop(features); | ||
| 660 | let bin = open(&library, DELETED); | ||
| 661 | let recycled = bin.shared.section.pages().unwrap()[0].0; | ||
| 662 | let restored = library | ||
| 663 | .move_page( | ||
| 664 | DELETED, | ||
| 665 | recycled, | ||
| 666 | "Features.one", | ||
| 667 | None, | ||
| 668 | 1, | ||
| 669 | None, | ||
| 670 | "Clover Test", | ||
| 671 | date, | ||
| 672 | ) | ||
| 673 | .unwrap(); | ||
| 674 | assert_eq!((restored.added, restored.copied), (None, None)); | ||
| 675 | assert!(bin.shared.section.pages().unwrap().is_empty()); | ||
| 676 | } | ||
| 677 | |||
| 621 | #[test] | 678 | #[test] |
| 622 | fn deleting_a_lone_section_page_still_creates_its_replacement_without_a_bin() { | 679 | fn deleting_a_lone_section_page_still_creates_its_replacement_without_a_bin() { |
| 623 | let directory = tempfile::tempdir().unwrap(); | 680 | let directory = tempfile::tempdir().unwrap(); |
| ... | @@ -4341,3 +4398,91 @@ fn a_provider_that_lists_but_cannot_open_opens_from_the_offline_copies() { | ... | @@ -4341,3 +4398,91 @@ fn a_provider_that_lists_but_cannot_open_opens_from_the_offline_copies() { |
| 4341 | assert!(stored_text(&file, space).contains("Offline")); | 4398 | assert!(stored_text(&file, space).contains("Offline")); |
| 4342 | closed(section); | 4399 | closed(section); |
| 4343 | } | 4400 | } |
| 4401 | |||
| 4402 | /// A page restored from a share's recycle bin while working offline waits in the cache and | ||
| 4403 | /// publishes once online: a cold reopen finds it, content and identity kept, in the section | ||
| 4404 | /// it was restored to, and Deleted Pages empty. `ONESTORE_SMB_LAB=HOST:PORT` names a guest | ||
| 4405 | /// share `agent` (`tools/w7/linux_vm.py up NAME`); the notebook goes in a fresh folder. | ||
| 4406 | #[test] | ||
| 4407 | #[ignore = "requires an owned Samba share at ONESTORE_SMB_LAB"] | ||
| 4408 | fn a_page_restored_offline_on_a_share_publishes_once_online() { | ||
| 4409 | const DELETED: &str = "OneNote_RecycleBin/OneNote_DeletedPages.one"; | ||
| 4410 | let date = ["Monday, October 19, 2026", "9:00 AM"]; | ||
| 4411 | let server = || library::Server { | ||
| 4412 | address: std::env::var("ONESTORE_SMB_LAB").unwrap(), | ||
| 4413 | share: "agent".into(), | ||
| 4414 | user: String::new(), | ||
| 4415 | password: String::new(), | ||
| 4416 | domain: String::new(), | ||
| 4417 | }; | ||
| 4418 | let root = format!("snowbound-recycle-{}", std::process::id()); | ||
| 4419 | let directory = tempfile::tempdir().unwrap(); | ||
| 4420 | let client = Arc::new(server().connect().unwrap()); | ||
| 4421 | client.create_directory(&root).unwrap(); | ||
| 4422 | let mut notebook = notebook::session::Notebook::open_smb( | ||
| 4423 | Arc::clone(&client), | ||
| 4424 | &root, | ||
| 4425 | directory.path().join("made"), | ||
| 4426 | ) | ||
| 4427 | .unwrap(); | ||
| 4428 | for (name, title) in [("Kept", "Restored over SMB"), ("Target", "Already there")] { | ||
| 4429 | let page = onestore::PageCreation::new(None, Some(title), "Clover Test").unwrap(); | ||
| 4430 | notebook.create_section("", name, &page).unwrap(); | ||
| 4431 | } | ||
| 4432 | drop(notebook); | ||
| 4433 | |||
| 4434 | let library = | ||
| 4435 | Arc::new(Library::server(server(), &root, &directory.path().join("cache")).unwrap()); | ||
| 4436 | library.tabs().unwrap(); | ||
| 4437 | let kept = open(&library, "Kept.one"); | ||
| 4438 | let deleted = space(&kept, "Restored over SMB"); | ||
| 4439 | let page = kept.shared.section.page(deleted).unwrap(); | ||
| 4440 | kept.delete_page(deleted, date[0], date[1]).unwrap(); | ||
| 4441 | drop(kept); | ||
| 4442 | // As the iOS sheet lists the bin, then opens Deleted Pages. | ||
| 4443 | assert_eq!(library.recycle_bin().unwrap()[0].path, DELETED); | ||
| 4444 | let bin = open(&library, DELETED); | ||
| 4445 | let recycled = bin.shared.section.pages().unwrap()[0].0; | ||
| 4446 | |||
| 4447 | sb_library_set_offline(&library, true); | ||
| 4448 | let restored = library | ||
| 4449 | .move_page( | ||
| 4450 | DELETED, | ||
| 4451 | recycled, | ||
| 4452 | "Target.one", | ||
| 4453 | None, | ||
| 4454 | 1, | ||
| 4455 | None, | ||
| 4456 | "Clover Test", | ||
| 4457 | date, | ||
| 4458 | ) | ||
| 4459 | .unwrap(); | ||
| 4460 | assert_eq!((restored.added, restored.copied), (None, None)); | ||
| 4461 | assert!( | ||
| 4462 | !bin.shared.section.pending().unwrap().is_empty(), | ||
| 4463 | "the bin's edit waits offline" | ||
| 4464 | ); | ||
| 4465 | drop(bin); | ||
| 4466 | sb_library_set_offline(&library, false); | ||
| 4467 | sb_library_sync_now(&library); | ||
| 4468 | library.close(Duration::from_secs(60)).unwrap(); | ||
| 4469 | drop(library); | ||
| 4470 | |||
| 4471 | let cold = Arc::new(Library::server(server(), &root, &directory.path().join("cold")).unwrap()); | ||
| 4472 | cold.tabs().unwrap(); | ||
| 4473 | let target = open(&cold, "Target.one"); | ||
| 4474 | let arrived = space(&target, "Restored over SMB"); | ||
| 4475 | assert_eq!( | ||
| 4476 | target.shared.section.page(arrived).unwrap().identity, | ||
| 4477 | page.identity | ||
| 4478 | ); | ||
| 4479 | drop(target); | ||
| 4480 | assert!( | ||
| 4481 | open(&cold, DELETED) | ||
| 4482 | .shared | ||
| 4483 | .section | ||
| 4484 | .pages() | ||
| 4485 | .unwrap() | ||
| 4486 | .is_empty() | ||
| 4487 | ); | ||
| 4488 | } |