Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
233d9e9e51 | ||
|
|
26272cda6c | ||
|
|
370abd58dc | ||
|
|
24594b24ae | ||
|
|
04f0713012 | ||
|
|
cc020bfb54 | ||
|
|
1e6043d12a | ||
|
|
834684f6d7 | ||
|
|
1c2a66169f | ||
|
|
cb5ff8b8da | ||
|
|
c57d98799a | ||
|
|
7d9d5850a4 | ||
|
|
a69ebbdd10 | ||
|
|
ddf7335894 | ||
|
|
140bd2eee3 | ||
|
|
2462cb24bd | ||
|
|
a1dd2b5a9b | ||
|
|
e9d6d4a907 | ||
|
|
6fa91e83f1 | ||
|
|
f239dffbcc | ||
|
|
e011a0d89f | ||
|
|
f2c4c05f27 | ||
|
|
8598aff7dd | ||
|
|
38a8db0e3e | ||
|
|
db8c0cb382 | ||
|
|
a7baf2313c | ||
|
|
7e0d7d020e | ||
|
|
0df4b3c5f9 | ||
|
|
14b9e0fe64 | ||
|
|
64864562ef | ||
|
|
ce3bfa217d | ||
|
|
593df5c401 | ||
|
|
fd6b2d3e85 | ||
|
|
7d445bb02c |
No files matched your search
@@ -44,6 +44,9 @@ jobs:
|
||||
- name: Formatting
|
||||
run: cargo fmt --all -- --check
|
||||
|
||||
- name: Shell scripts of the release tarball
|
||||
run: shellcheck packaging/tarball/*.sh
|
||||
|
||||
- name: Lints
|
||||
run: cargo clippy --workspace --all-targets --locked -- -D warnings
|
||||
|
||||
@@ -102,14 +105,17 @@ jobs:
|
||||
- name: Simulation runs
|
||||
run: 'cargo test -p pdfs-fuse --lib --locked sim:: -- --ignored --test-threads=1'
|
||||
|
||||
# A hung step writes every daemon thread's stack next to the run's
|
||||
# state; without them a hang that does not replay cannot be told apart.
|
||||
- name: Keep the stacks of a hung run
|
||||
# Retain the operation trace and daemon logs for the failing seed, plus
|
||||
# every daemon thread's stack if the watchdog caught a hang.
|
||||
- name: Keep simulation failure diagnostics
|
||||
if: failure()
|
||||
uses: actions/upload-artifact@v7
|
||||
with:
|
||||
name: simulation-stacks
|
||||
path: /tmp/pdfs-sim-*/stacks.txt
|
||||
name: simulation-diagnostics
|
||||
path: |
|
||||
/tmp/pdfs-sim-*/steps.log
|
||||
/tmp/pdfs-sim-*/daemon.log
|
||||
/tmp/pdfs-sim-*/stacks.txt
|
||||
if-no-files-found: ignore
|
||||
|
||||
# Keeps the release-profile dependencies cached on main, where the release
|
||||
|
||||
@@ -119,23 +119,22 @@ jobs:
|
||||
echo "VERSION=$VERSION" >> $GITHUB_ENV
|
||||
echo "Building version: $VERSION"
|
||||
|
||||
- name: Package raw binaries (.tar.gz)
|
||||
# Binaries plus everything around them, with install.sh for a home
|
||||
# directory install (immutable distributions, anything without a package).
|
||||
- name: Package the installable tarball (.tar.gz)
|
||||
run: |
|
||||
mkdir -p dist/binaries
|
||||
cp target/release/pdfs dist/binaries/
|
||||
cp target/release/pdfs-tray dist/binaries/
|
||||
cp target/release/pdfs-app dist/binaries/
|
||||
cp target/release/pdfs-prompt dist/binaries/
|
||||
po/build.sh dist/binaries/locale
|
||||
|
||||
# Create tarball
|
||||
tar -czf proton-drive-linux-${{ env.VERSION }}-x86_64.tar.gz -C dist/binaries .
|
||||
tarball=$(packaging/tarball/build.sh target/release "${{ env.VERSION }}" .)
|
||||
packaging/tarball/test.sh "$tarball"
|
||||
|
||||
# Every crate the build needs, so COPR can build the spec without network.
|
||||
- name: Package vendored crates (.tar.xz)
|
||||
run: |
|
||||
cargo vendor --locked dist/vendor > /dev/null
|
||||
tar -cJf proton-drive-linux-vendor-${{ env.VERSION }}.tar.xz -C dist vendor
|
||||
mkdir -p dist/.cargo
|
||||
(
|
||||
cd dist
|
||||
cargo vendor --locked --manifest-path ../Cargo.toml vendor > .cargo/config.toml
|
||||
)
|
||||
tar -cJf proton-drive-linux-vendor-${{ env.VERSION }}.tar.xz -C dist vendor .cargo/config.toml
|
||||
|
||||
- name: Package Debian package (.deb)
|
||||
run: |
|
||||
@@ -157,6 +156,7 @@ jobs:
|
||||
cp packaging/io.narl.proton-drive-linux.desktop deb/usr/share/applications/
|
||||
cp packaging/io.narl.proton-drive-linux-tray.desktop deb/etc/xdg/autostart/
|
||||
cp packaging/io.narl.proton-drive-linux.svg deb/usr/share/icons/hicolor/scalable/apps/
|
||||
install -Dm644 packaging/io.narl.proton-drive-linux.policy deb/usr/share/polkit-1/actions/io.narl.proton-drive-linux.policy
|
||||
cp packaging/proton-drive.service deb/usr/lib/systemd/user/
|
||||
cp LICENSE deb/usr/share/licenses/proton-drive-linux/
|
||||
po/build.sh deb/usr/share/locale
|
||||
@@ -176,7 +176,7 @@ jobs:
|
||||
Priority: optional
|
||||
Architecture: amd64
|
||||
Maintainer: Nils Pukropp <contact@narl.io>
|
||||
Depends: fuse3, libgtk-4-1 (>= 4.12.0), libadwaita-1-0 (>= 1.5.0), libsecret-1-0, libwebkitgtk-6.0-4, libimage-exiftool-perl
|
||||
Depends: polkitd, fuse3, libgtk-4-1 (>= 4.12.0), libadwaita-1-0 (>= 1.5.0), libsecret-1-0, libwebkitgtk-6.0-4, libimage-exiftool-perl
|
||||
Installed-Size: ${INSTALLED_SIZE}
|
||||
Homepage: https://proton-drive.narl.io
|
||||
Description: Unofficial Proton Drive client for Linux
|
||||
|
||||
@@ -49,6 +49,7 @@ dependencies = [
|
||||
"cipher 0.5.2",
|
||||
"cpubits",
|
||||
"cpufeatures 0.3.1",
|
||||
"zeroize",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -77,6 +78,7 @@ dependencies = [
|
||||
"ctr 0.10.1",
|
||||
"ctutils",
|
||||
"ghash 0.6.0",
|
||||
"zeroize",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -180,6 +182,17 @@ version = "1.0.104"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "330a5ed07fa54e4702c9d6c4174f74427fc0ef6e214bbd677ae50a5099946470"
|
||||
|
||||
[[package]]
|
||||
name = "apple-native-keyring-store"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2b350bfd03649e07aa05c0a81b3e15934374e585c98204a57e20b9d49f49bb9a"
|
||||
dependencies = [
|
||||
"keyring-core",
|
||||
"log",
|
||||
"security-framework",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "arbitrary"
|
||||
version = "1.5.0"
|
||||
@@ -1878,6 +1891,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2eecf2d5dc9b66b732b97707a0210906b1d30523eb773193ab777c0c84b3e8d5"
|
||||
dependencies = [
|
||||
"polyval 0.7.3",
|
||||
"zeroize",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2237,6 +2251,12 @@ version = "1.10.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87"
|
||||
|
||||
[[package]]
|
||||
name = "httpdate"
|
||||
version = "1.0.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9"
|
||||
|
||||
[[package]]
|
||||
name = "hybrid-array"
|
||||
version = "0.4.15"
|
||||
@@ -2260,6 +2280,7 @@ dependencies = [
|
||||
"http",
|
||||
"http-body",
|
||||
"httparse",
|
||||
"httpdate",
|
||||
"itoa",
|
||||
"pin-project-lite",
|
||||
"smallvec",
|
||||
@@ -3582,7 +3603,7 @@ checksum = "2ee67f1008b1ba2321834326597b8e186293b049a023cdef258527550b9935b4"
|
||||
|
||||
[[package]]
|
||||
name = "pdfs-cli"
|
||||
version = "3.8.0"
|
||||
version = "3.9.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"clap",
|
||||
@@ -3599,40 +3620,46 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "pdfs-core"
|
||||
version = "3.8.0"
|
||||
version = "3.9.0"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"base64 0.23.1",
|
||||
"chrono",
|
||||
"dbus-secret-service",
|
||||
"dbus-secret-service-keyring-store",
|
||||
"directories",
|
||||
"ignore",
|
||||
"kamadak-exif",
|
||||
"keyring-core",
|
||||
"libc",
|
||||
"parking_lot 0.13.0",
|
||||
"proton-auth-rs",
|
||||
"proton-base-rs",
|
||||
"proton-drive-rs",
|
||||
"proton-gallery-rs",
|
||||
"proton-sdk",
|
||||
"rusqlite",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"sha1 0.11.0",
|
||||
"sha2 0.11.1",
|
||||
"shell-words",
|
||||
"thiserror 2.0.21",
|
||||
"tokio",
|
||||
"tracing",
|
||||
"zeroize",
|
||||
"zip",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pdfs-fuse"
|
||||
version = "3.8.0"
|
||||
version = "3.9.0"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"base64 0.23.1",
|
||||
"fuser",
|
||||
"futures",
|
||||
"getrandom 0.4.3",
|
||||
"http-body-util",
|
||||
"hyper",
|
||||
"hyper-util",
|
||||
"image",
|
||||
"libc",
|
||||
"lofty",
|
||||
@@ -3640,21 +3667,26 @@ dependencies = [
|
||||
"parking_lot 0.13.0",
|
||||
"pdfs-core",
|
||||
"proton-drive-rs",
|
||||
"proton-gallery-app-rs",
|
||||
"proton-gallery-rs",
|
||||
"rustix",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"sha1 0.11.0",
|
||||
"tokio",
|
||||
"tracing",
|
||||
"tracing-subscriber",
|
||||
"zeroize",
|
||||
"zip",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pdfs-gui"
|
||||
version = "3.8.0"
|
||||
version = "3.9.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"async-channel",
|
||||
"base64 0.23.1",
|
||||
"gettext-rs",
|
||||
"gtk4",
|
||||
"kamadak-exif",
|
||||
@@ -3662,6 +3694,7 @@ dependencies = [
|
||||
"libadwaita",
|
||||
"pangocairo",
|
||||
"pdfs-core",
|
||||
"proton-gallery-rs",
|
||||
"reqwest",
|
||||
"serde",
|
||||
"serde_json",
|
||||
@@ -3823,6 +3856,7 @@ dependencies = [
|
||||
"cpubits",
|
||||
"cpufeatures 0.3.1",
|
||||
"universal-hash 0.6.1",
|
||||
"zeroize",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -3890,10 +3924,36 @@ dependencies = [
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proton-drive-rs"
|
||||
version = "0.12.0"
|
||||
name = "proton-auth-rs"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4265c2cf3bdc59ee273d7363c8b6a7cb4e98be6102ffa18144c4d8ebda00737b"
|
||||
checksum = "e140db8b4444e50c818c9793c2078b57c16c5b6c285a8d4bbd74886f41b05c6f"
|
||||
dependencies = [
|
||||
"apple-native-keyring-store",
|
||||
"dbus-secret-service",
|
||||
"dbus-secret-service-keyring-store",
|
||||
"keyring-core",
|
||||
"thiserror 2.0.21",
|
||||
"tracing",
|
||||
"windows-native-keyring-store",
|
||||
"zeroize",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proton-base-rs"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "451151bb1025ea5cb362f69e2bfb2d45afed603e5c6daa3dc752333a7c29c878"
|
||||
dependencies = [
|
||||
"rusqlite",
|
||||
"thiserror 2.0.21",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proton-drive-rs"
|
||||
version = "0.12.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d05ad4be849ce2104759631063dd06867fbe6b6f0e5c37a172a84b5a90203fa7"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"base64 0.23.1",
|
||||
@@ -3918,10 +3978,76 @@ dependencies = [
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proton-sdk"
|
||||
version = "0.12.0"
|
||||
name = "proton-gallery-app-rs"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fb98ab3e336ed95f82368a50348dad00e5fc919e982d748e83e844afcadbd5d8"
|
||||
checksum = "d6d18d11266ab2be5ab2f4b4040941caf2736c257e13909af7be8ea331892d59"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"futures-util",
|
||||
"hex",
|
||||
"proton-drive-rs",
|
||||
"proton-gallery-drive-rs",
|
||||
"proton-gallery-rs",
|
||||
"proton-sdk",
|
||||
"serde_json",
|
||||
"sha2 0.11.1",
|
||||
"tempfile",
|
||||
"thiserror 2.0.21",
|
||||
"tokio",
|
||||
"tracing",
|
||||
"zeroize",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proton-gallery-drive-rs"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "535a14f63fd542701d2606acb971d4a7e8f235ca7b9439fea8c80a3f26110186"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"hex",
|
||||
"proton-drive-rs",
|
||||
"proton-gallery-rs",
|
||||
"proton-sdk",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"sha2 0.11.1",
|
||||
"thiserror 2.0.21",
|
||||
"tokio",
|
||||
"tracing",
|
||||
"zeroize",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proton-gallery-rs"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dc9c9bbb76a5fba4071ee90de4aada71c292c0e408024ddfb04a12869291404a"
|
||||
dependencies = [
|
||||
"aes-gcm 0.11.1",
|
||||
"async-trait",
|
||||
"getrandom 0.4.3",
|
||||
"hex",
|
||||
"kamadak-exif",
|
||||
"rusqlite",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"sha2 0.11.1",
|
||||
"tempfile",
|
||||
"thiserror 2.0.21",
|
||||
"tokio",
|
||||
"tokio-util",
|
||||
"tracing",
|
||||
"zeroize",
|
||||
"zip",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proton-sdk"
|
||||
version = "0.12.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "80c381e9066c0bca3c32597df2e902eecaa4c6e05e202e70ec9d0ac2eec78bfe"
|
||||
dependencies = [
|
||||
"aes-gcm 0.11.1",
|
||||
"async-trait",
|
||||
@@ -4804,6 +4930,12 @@ dependencies = [
|
||||
"lazy_static",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "shell-words"
|
||||
version = "1.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dc6fe69c597f9c37bfeeeeeb33da3530379845f10be461a66d16d03eca2ded77"
|
||||
|
||||
[[package]]
|
||||
name = "shlex"
|
||||
version = "2.0.1"
|
||||
@@ -5183,6 +5315,7 @@ dependencies = [
|
||||
"bytes",
|
||||
"futures-core",
|
||||
"futures-sink",
|
||||
"futures-util",
|
||||
"libc",
|
||||
"pin-project-lite",
|
||||
"tokio",
|
||||
@@ -5768,6 +5901,19 @@ version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
|
||||
|
||||
[[package]]
|
||||
name = "windows-native-keyring-store"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "063426e76fdec7438d56bb777f67e318a84a25c707b07e575cb8b78e10c028f8"
|
||||
dependencies = [
|
||||
"byteorder",
|
||||
"keyring-core",
|
||||
"regex",
|
||||
"windows-sys 0.61.2",
|
||||
"zeroize",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-result"
|
||||
version = "0.4.1"
|
||||
|
||||
@@ -3,7 +3,7 @@ resolver = "2"
|
||||
members = ["crates/pdfs-core", "crates/pdfs-fuse", "crates/pdfs-cli", "crates/pdfs-gui"]
|
||||
|
||||
[workspace.package]
|
||||
version = "3.8.0"
|
||||
version = "3.9.0"
|
||||
edition = "2024"
|
||||
license = "MIT"
|
||||
authors = ["Nils Pukropp <contact@narl.io>"]
|
||||
@@ -15,8 +15,10 @@ keywords = ["proton", "drive", "fuse", "sync", "linux"]
|
||||
categories = ["filesystem", "command-line-utilities"]
|
||||
|
||||
[workspace.dependencies]
|
||||
proton-sdk = { version = "0.12.0" }
|
||||
proton-drive-rs = { version = "0.12.0" }
|
||||
proton-sdk = { version = "0.12.1" }
|
||||
proton-drive-rs = { version = "0.12.1" }
|
||||
proton-gallery-app-rs = "0.1.0"
|
||||
proton-gallery-rs = "0.1.1"
|
||||
chrono = { version = "0.4", default-features = false, features = ["std"] }
|
||||
|
||||
# Internal crates.
|
||||
@@ -39,6 +41,8 @@ tracing = "0.1"
|
||||
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
|
||||
directories = "6"
|
||||
ignore = "0.4"
|
||||
# Command lines typed into Preferences, split and shown the way a shell would.
|
||||
shell-words = "1"
|
||||
sha2 = "0.11"
|
||||
# Google Takeout exports are zip sets; the importer reads their central
|
||||
# directories and streams entries out without extracting to disk first.
|
||||
@@ -59,7 +63,14 @@ rusqlite = { version = "0.41", features = ["bundled"] }
|
||||
# Secret Service store is the one keyring 3's `sync-secret-service` wrapped, and
|
||||
# with no `target` it matches items v3 wrote, so existing logins survive.
|
||||
keyring-core = "1"
|
||||
# The keyring store all three apps share: reconnects after a Secret Service
|
||||
# restart (B285) and replaces items instead of editing them (B291).
|
||||
proton-auth-rs = "0.1"
|
||||
proton-base-rs = "0.1"
|
||||
dbus-secret-service-keyring-store = { version = "1", features = ["crypto-rust"] }
|
||||
# The same Secret Service client the store wraps, used directly to replace an
|
||||
# item instead of editing it, which oo7 before 0.7.0 kept only in memory (B291).
|
||||
dbus-secret-service = { version = "4.1", features = ["crypto-rust"] }
|
||||
clap = { version = "4", features = ["derive"] }
|
||||
# `unstable-dynamic`: Tab calls `pdfs` back, so arguments complete from the
|
||||
# running service. Only `pdfs-cli/src/complete.rs` uses it.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<div align="center">
|
||||
|
||||
<img src="images/logo.svg" alt="" width="112" height="112">
|
||||
<a href="images/logo.svg"><img src="images/logo.svg" alt="Proton Drive for Linux icon" width="128" height="128"></a>
|
||||
|
||||
# Proton Drive for Linux
|
||||
|
||||
@@ -77,7 +77,8 @@ scriptable CLI.
|
||||
| Arch Linux | [`proton-drive-for-linux`](https://aur.archlinux.org/packages/proton-drive-for-linux) (also `-bin` and `-git`) in the AUR |
|
||||
| Debian, Ubuntu 24.04 or newer | `.deb` from the [latest release](https://github.com/narrrl/proton-drive-linux/releases/latest) |
|
||||
| NixOS | The flake in this repository: see [Installation → NixOS](docs/INSTALL.md#nixos-flake) |
|
||||
| Anything else | [Build from source](docs/INSTALL.md#build-from-source) |
|
||||
| Fedora Atomic (Silverblue, Kinoite, Bazzite, Bluefin) | The COPR repository, layered with `rpm-ostree`: see [Installation → Fedora Atomic](docs/INSTALL.md#fedora-atomic-silverblue-kinoite-bazzite-bluefin) |
|
||||
| Anything else, immutable ones included | `.tar.gz` from the [latest release](https://github.com/narrrl/proton-drive-linux/releases/latest), installed into your home folder by its `install.sh`: see [Installation → Other distributions](docs/INSTALL.md#other-distributions), or [build from source](docs/INSTALL.md#build-from-source) |
|
||||
|
||||
**Fedora**
|
||||
|
||||
|
||||
@@ -15,8 +15,8 @@ use pdfs_core::cache::ContentCache;
|
||||
use pdfs_core::config::AppDirs;
|
||||
use pdfs_core::control::{
|
||||
ConflictKeep, ErrorKind, LinkChange, MountKind, RefreshScope, Request as CtlRequest,
|
||||
Response as CtlResponse, RestoreItem as CtlRestoreItem, ShareEntryKind, SyncIssue, SyncPhase,
|
||||
daemon_outdated, pending_summary,
|
||||
Response as CtlResponse, RestoreItem as CtlRestoreItem, ShareEntryKind, SyncFolderInfo,
|
||||
SyncIssue, SyncPhase, daemon_outdated, pending_summary,
|
||||
};
|
||||
use pdfs_core::db::Db;
|
||||
use pdfs_core::service;
|
||||
@@ -751,6 +751,42 @@ enum ConflictCmd {
|
||||
},
|
||||
}
|
||||
|
||||
/// `pdfs sync ignore`: the patterns in `ignore_patterns`, for every synced
|
||||
/// folder, or with `--folder` the ones in that folder's own `.pdfsignore`.
|
||||
#[derive(Subcommand, Debug)]
|
||||
enum IgnoreCmd {
|
||||
/// List the patterns every synced folder leaves out, or one folder's own.
|
||||
List {
|
||||
/// List the own patterns of the synced folder holding this path.
|
||||
#[arg(long, value_hint = ValueHint::DirPath)]
|
||||
folder: Option<PathBuf>,
|
||||
},
|
||||
/// Leave out files matching a gitignore-style pattern, e.g. `*.db` or `build/`.
|
||||
Add {
|
||||
/// The pattern; end it with `/` to match folders only.
|
||||
pattern: String,
|
||||
/// Add it only for the synced folder holding this path.
|
||||
#[arg(long, value_hint = ValueHint::DirPath)]
|
||||
folder: Option<PathBuf>,
|
||||
},
|
||||
/// Stop leaving out files matching a pattern.
|
||||
Remove {
|
||||
/// The pattern, as `sync ignore list` shows it.
|
||||
pattern: String,
|
||||
/// Remove it from the own patterns of the synced folder holding this path.
|
||||
#[arg(long, value_hint = ValueHint::DirPath)]
|
||||
folder: Option<PathBuf>,
|
||||
},
|
||||
/// Go back to the built-in patterns.
|
||||
Reset,
|
||||
/// Say whether a file in a synced folder is synced, and which pattern decides.
|
||||
Check {
|
||||
/// A file or folder inside a synced folder.
|
||||
#[arg(value_hint = ValueHint::AnyPath)]
|
||||
path: PathBuf,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Subcommand)]
|
||||
enum SyncCmd {
|
||||
/// Add a local folder to this machine's device and upload its contents.
|
||||
@@ -849,6 +885,11 @@ enum SyncCmd {
|
||||
#[arg(add = ArgValueCandidates::new(complete::queue_id))]
|
||||
id: Option<i64>,
|
||||
},
|
||||
/// Show or change the patterns every synced folder leaves out, or check a path.
|
||||
Ignore {
|
||||
#[command(subcommand)]
|
||||
action: IgnoreCmd,
|
||||
},
|
||||
/// Switch a folder between full-copy sync and on-demand (FUSE, no local storage).
|
||||
Mode {
|
||||
/// Synced-folder id (from `sync list`).
|
||||
@@ -1324,6 +1365,7 @@ fn cmd_sync(action: SyncCmd) -> Result<()> {
|
||||
SyncCmd::Issues => return cmd_sync_issues(),
|
||||
SyncCmd::Export { id, dest } => return cmd_sync_export(id, &dest),
|
||||
SyncCmd::Limit { up, down } => return cmd_sync_limit(up, down),
|
||||
SyncCmd::Ignore { action } => return cmd_sync_ignore(action),
|
||||
SyncCmd::Discard { id, yes } => {
|
||||
if !yes {
|
||||
confirm(&format!(
|
||||
@@ -1469,6 +1511,7 @@ fn issue_text(issue: SyncIssue) -> &'static str {
|
||||
"you can no longer change this on Proton Drive, for example because a share was \
|
||||
revoked. Save a copy to keep the content."
|
||||
}
|
||||
SyncIssue::Trashed => "restore the item or folder from Trash, then retry the move.",
|
||||
SyncIssue::Missing => {
|
||||
"the file or its folder is gone from Proton Drive. Save a copy to keep the content."
|
||||
}
|
||||
@@ -2653,6 +2696,7 @@ fn mount_once(mountpoint: Option<PathBuf>) -> Result<pdfs_fuse::MountOutcome> {
|
||||
db,
|
||||
pdfs_fuse::MountOptions {
|
||||
username,
|
||||
gallery_session: Some(session.clone()),
|
||||
sweep_mode: config.resolved_conflict_sweep(),
|
||||
upload_limit: config.upload_limit.unwrap_or(0),
|
||||
download_limit: config.download_limit.unwrap_or(0),
|
||||
@@ -3699,6 +3743,173 @@ fn cmd_sync_limit(up: Option<u64>, down: Option<u64>) -> Result<()> {
|
||||
})?)
|
||||
}
|
||||
|
||||
fn cmd_sync_ignore(action: IgnoreCmd) -> Result<()> {
|
||||
use pdfs_core::syncignore::{
|
||||
DEFAULT_IGNORE_PATTERNS, FolderRules, IgnoreRules, RuleSource, Verdict, add_folder_pattern,
|
||||
check_pattern, remove_folder_pattern,
|
||||
};
|
||||
let dirs = AppDirs::new()?;
|
||||
let change = |edit: &dyn Fn(&mut Vec<String>)| -> Result<()> {
|
||||
dirs.change_ignore_patterns(edit)?;
|
||||
// The next pass picks the change up anyway; this only hurries it.
|
||||
let _ = control_request(CtlRequest::SyncNow { id: None });
|
||||
Ok(())
|
||||
};
|
||||
let valid = |pattern: &str| -> Result<String> {
|
||||
let pattern = pattern.trim();
|
||||
if pattern.is_empty() || pattern.starts_with('#') {
|
||||
bail!("not a pattern: `{pattern}`");
|
||||
}
|
||||
check_pattern(pattern).map_err(|e| anyhow!("not a valid pattern: {e}"))?;
|
||||
Ok(pattern.to_string())
|
||||
};
|
||||
match action {
|
||||
IgnoreCmd::List { folder: None } => {
|
||||
let config = dirs.load_config();
|
||||
let list = config.resolved_ignore_patterns();
|
||||
if list.is_empty() {
|
||||
println!("No patterns: every file is synced.");
|
||||
}
|
||||
for pattern in list {
|
||||
if DEFAULT_IGNORE_PATTERNS.contains(&pattern.as_str()) {
|
||||
println!("{pattern} (built in)");
|
||||
} else {
|
||||
println!("{pattern}");
|
||||
}
|
||||
}
|
||||
}
|
||||
IgnoreCmd::List {
|
||||
folder: Some(folder),
|
||||
} => {
|
||||
let (_, root) = mirror_folder_of(&folder)?;
|
||||
let rules = FolderRules::read(&root)?;
|
||||
let patterns = rules.patterns();
|
||||
if patterns.is_empty() {
|
||||
println!(
|
||||
"{} has no own patterns; the ones for all synced folders apply.",
|
||||
root.display()
|
||||
);
|
||||
}
|
||||
for pattern in patterns {
|
||||
println!("{pattern}");
|
||||
}
|
||||
}
|
||||
IgnoreCmd::Add {
|
||||
pattern,
|
||||
folder: None,
|
||||
} => {
|
||||
let pattern = valid(&pattern)?;
|
||||
change(&|list| {
|
||||
if !list.contains(&pattern) {
|
||||
list.push(pattern.clone());
|
||||
}
|
||||
})?;
|
||||
}
|
||||
IgnoreCmd::Add {
|
||||
pattern,
|
||||
folder: Some(folder),
|
||||
} => {
|
||||
let pattern = valid(&pattern)?;
|
||||
let (id, root) = mirror_folder_of(&folder)?;
|
||||
if add_folder_pattern(&root, &pattern)? {
|
||||
let _ = control_request(CtlRequest::SyncNow { id: Some(id) });
|
||||
} else {
|
||||
println!("`{pattern}` is already in {}/.pdfsignore.", root.display());
|
||||
}
|
||||
}
|
||||
IgnoreCmd::Remove {
|
||||
pattern,
|
||||
folder: None,
|
||||
} => {
|
||||
let pattern = pattern.trim().to_string();
|
||||
let list = dirs.load_config().resolved_ignore_patterns();
|
||||
if !list.contains(&pattern) {
|
||||
bail!("`{pattern}` is not in the list; see `pdfs sync ignore list`");
|
||||
}
|
||||
change(&|list| list.retain(|p| *p != pattern))?;
|
||||
}
|
||||
IgnoreCmd::Remove {
|
||||
pattern,
|
||||
folder: Some(folder),
|
||||
} => {
|
||||
let (id, root) = mirror_folder_of(&folder)?;
|
||||
if !remove_folder_pattern(&root, &pattern)? {
|
||||
bail!(
|
||||
"`{}` is not among the own patterns of {}; see `pdfs sync ignore list --folder {}`",
|
||||
pattern.trim(),
|
||||
root.display(),
|
||||
root.display()
|
||||
);
|
||||
}
|
||||
let _ = control_request(CtlRequest::SyncNow { id: Some(id) });
|
||||
}
|
||||
IgnoreCmd::Reset => change(&|list| {
|
||||
*list = DEFAULT_IGNORE_PATTERNS
|
||||
.iter()
|
||||
.map(|p| (*p).to_string())
|
||||
.collect()
|
||||
})?,
|
||||
IgnoreCmd::Check { path } => {
|
||||
let path = std::path::absolute(&path)?;
|
||||
let folder = synced_folder_of(&path)?;
|
||||
if folder.mode != "mirror" {
|
||||
println!(
|
||||
"{} is online only; patterns apply only to folders kept on this computer.",
|
||||
folder.local_path
|
||||
);
|
||||
return Ok(());
|
||||
}
|
||||
let root = PathBuf::from(&folder.local_path);
|
||||
let rel = path.strip_prefix(&root).unwrap_or(&path).to_string_lossy();
|
||||
let globals = dirs.load_config().resolved_ignore_patterns();
|
||||
let rules = IgnoreRules::load(&root, &globals);
|
||||
let source = |source: &RuleSource| match source {
|
||||
RuleSource::AllFolders => "the patterns for all synced folders".to_string(),
|
||||
RuleSource::ThisFolder => format!("{}/.pdfsignore", root.display()),
|
||||
};
|
||||
match rules.explain(&rel, path.is_dir()) {
|
||||
Verdict::Synced => println!("Synced: no pattern matches it."),
|
||||
Verdict::Excluded { pattern, source: s } => {
|
||||
println!("Not synced: excluded by `{pattern}` in {}.", source(&s))
|
||||
}
|
||||
Verdict::Included { pattern, source: s } => {
|
||||
println!("Synced: `{pattern}` in {} includes it again.", source(&s))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// The synced folder holding `path`: the innermost one, as the daemon lists
|
||||
/// them.
|
||||
fn synced_folder_of(path: &Path) -> Result<SyncFolderInfo> {
|
||||
let path = std::path::absolute(path)?;
|
||||
let folders = match control_request(CtlRequest::ListSyncFolders)? {
|
||||
CtlResponse::SyncFolders { items } => items,
|
||||
CtlResponse::Error { message, kind } => bail!("{}", cli_error(kind, &message)),
|
||||
other => bail!("unexpected reply: {other:?}"),
|
||||
};
|
||||
folders
|
||||
.into_iter()
|
||||
.filter(|f| path.starts_with(&f.local_path))
|
||||
.max_by_key(|f| f.local_path.len())
|
||||
.ok_or_else(|| anyhow!("{} is not in a synced folder", path.display()))
|
||||
}
|
||||
|
||||
/// The id and root of the synced folder kept on this computer that holds
|
||||
/// `path`. Own patterns mean nothing to an online-only folder.
|
||||
fn mirror_folder_of(path: &Path) -> Result<(i64, PathBuf)> {
|
||||
let folder = synced_folder_of(path)?;
|
||||
if folder.mode != "mirror" {
|
||||
bail!(
|
||||
"{} is online only; patterns apply only to folders kept on this computer",
|
||||
folder.local_path
|
||||
);
|
||||
}
|
||||
Ok((folder.id, PathBuf::from(folder.local_path)))
|
||||
}
|
||||
|
||||
/// How long the oldest write may wait to upload before `diagnose` calls it
|
||||
/// out. Under a day it is a slow link or a big file; past it, something is
|
||||
/// holding the queue.
|
||||
@@ -4646,6 +4857,41 @@ mod login_wait_tests {
|
||||
Command::ImportGooglePhotos { resume: true, .. }
|
||||
));
|
||||
assert!(Cli::try_parse_from(["pdfs", "import-google-photos"]).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sync_ignore_takes_a_pattern_that_looks_like_an_option_after_dashes() {
|
||||
let cli = Cli::try_parse_from(["pdfs", "sync", "ignore", "add", "--", "-temp*"]).unwrap();
|
||||
assert!(matches!(
|
||||
cli.command,
|
||||
Command::Sync {
|
||||
action: SyncCmd::Ignore {
|
||||
action: IgnoreCmd::Add {
|
||||
ref pattern,
|
||||
folder: None
|
||||
}
|
||||
}
|
||||
} if pattern == "-temp*"
|
||||
));
|
||||
assert!(Cli::try_parse_from(["pdfs", "sync", "ignore", "add"]).is_err());
|
||||
assert!(Cli::try_parse_from(["pdfs", "sync", "ignore", "reset"]).is_ok());
|
||||
let cli =
|
||||
Cli::try_parse_from(["pdfs", "sync", "ignore", "add", "*.db", "--folder", "Work"])
|
||||
.unwrap();
|
||||
assert!(matches!(
|
||||
cli.command,
|
||||
Command::Sync {
|
||||
action: SyncCmd::Ignore {
|
||||
action: IgnoreCmd::Add {
|
||||
ref pattern,
|
||||
folder: Some(ref folder)
|
||||
}
|
||||
}
|
||||
} if pattern == "*.db" && folder == Path::new("Work")
|
||||
));
|
||||
assert!(
|
||||
Cli::try_parse_from(["pdfs", "sync", "ignore", "list", "--folder", "Work"]).is_ok()
|
||||
);
|
||||
assert!(
|
||||
Cli::try_parse_from(["pdfs", "import-google-photos", "--resume", "a.zip"]).is_err()
|
||||
);
|
||||
|
||||
@@ -12,6 +12,7 @@ description = "Core auth/session/config for the Proton Drive Linux client"
|
||||
[dependencies]
|
||||
proton-sdk.workspace = true
|
||||
proton-drive-rs.workspace = true
|
||||
proton-gallery-rs.workspace = true
|
||||
chrono.workspace = true
|
||||
tokio.workspace = true
|
||||
serde.workspace = true
|
||||
@@ -20,15 +21,16 @@ thiserror.workspace = true
|
||||
tracing.workspace = true
|
||||
directories.workspace = true
|
||||
ignore.workspace = true
|
||||
shell-words.workspace = true
|
||||
sha2.workspace = true
|
||||
sha1.workspace = true
|
||||
zip.workspace = true
|
||||
rusqlite.workspace = true
|
||||
keyring-core.workspace = true
|
||||
proton-auth-rs = { workspace = true, features = ["keyring"] }
|
||||
proton-base-rs.workspace = true
|
||||
dbus-secret-service-keyring-store.workspace = true
|
||||
dbus-secret-service.workspace = true
|
||||
parking_lot.workspace = true
|
||||
async-trait.workspace = true
|
||||
libc.workspace = true
|
||||
zeroize.workspace = true
|
||||
base64.workspace = true
|
||||
exif = { version = "0.6", package = "kamadak-exif" }
|
||||
@@ -1,250 +0,0 @@
|
||||
AD Andorra
|
||||
AE United Arab Emirates
|
||||
AF Afghanistan
|
||||
AG Antigua and Barbuda
|
||||
AI Anguilla
|
||||
AL Albania
|
||||
AM Armenia
|
||||
AO Angola
|
||||
AQ Antarctica
|
||||
AR Argentina
|
||||
AS American Samoa
|
||||
AT Austria
|
||||
AU Australia
|
||||
AW Aruba
|
||||
AX Åland Islands
|
||||
AZ Azerbaijan
|
||||
BA Bosnia and Herzegovina
|
||||
BB Barbados
|
||||
BD Bangladesh
|
||||
BE Belgium
|
||||
BF Burkina Faso
|
||||
BG Bulgaria
|
||||
BH Bahrain
|
||||
BI Burundi
|
||||
BJ Benin
|
||||
BL Saint Barthélemy
|
||||
BM Bermuda
|
||||
BN Brunei Darussalam
|
||||
BO Bolivia, Plurinational State of
|
||||
BQ Bonaire, Sint Eustatius and Saba
|
||||
BR Brazil
|
||||
BS Bahamas
|
||||
BT Bhutan
|
||||
BV Bouvet Island
|
||||
BW Botswana
|
||||
BY Belarus
|
||||
BZ Belize
|
||||
CA Canada
|
||||
CC Cocos (Keeling) Islands
|
||||
CD Congo, The Democratic Republic of the
|
||||
CF Central African Republic
|
||||
CG Congo
|
||||
CH Switzerland
|
||||
CI Côte d'Ivoire
|
||||
CK Cook Islands
|
||||
CL Chile
|
||||
CM Cameroon
|
||||
CN China
|
||||
CO Colombia
|
||||
CR Costa Rica
|
||||
CU Cuba
|
||||
CV Cabo Verde
|
||||
CW Curaçao
|
||||
CX Christmas Island
|
||||
CY Cyprus
|
||||
CZ Czechia
|
||||
DE Germany
|
||||
DJ Djibouti
|
||||
DK Denmark
|
||||
DM Dominica
|
||||
DO Dominican Republic
|
||||
DZ Algeria
|
||||
EC Ecuador
|
||||
EE Estonia
|
||||
EG Egypt
|
||||
EH Western Sahara
|
||||
ER Eritrea
|
||||
ES Spain
|
||||
ET Ethiopia
|
||||
FI Finland
|
||||
FJ Fiji
|
||||
FK Falkland Islands (Malvinas)
|
||||
FM Micronesia, Federated States of
|
||||
FO Faroe Islands
|
||||
FR France
|
||||
GA Gabon
|
||||
GB United Kingdom
|
||||
GD Grenada
|
||||
GE Georgia
|
||||
GF French Guiana
|
||||
GG Guernsey
|
||||
GH Ghana
|
||||
GI Gibraltar
|
||||
GL Greenland
|
||||
GM Gambia
|
||||
GN Guinea
|
||||
GP Guadeloupe
|
||||
GQ Equatorial Guinea
|
||||
GR Greece
|
||||
GS South Georgia and the South Sandwich Islands
|
||||
GT Guatemala
|
||||
GU Guam
|
||||
GW Guinea-Bissau
|
||||
GY Guyana
|
||||
HK Hong Kong
|
||||
HM Heard Island and McDonald Islands
|
||||
HN Honduras
|
||||
HR Croatia
|
||||
HT Haiti
|
||||
HU Hungary
|
||||
ID Indonesia
|
||||
IE Ireland
|
||||
IL Israel
|
||||
IM Isle of Man
|
||||
IN India
|
||||
IO British Indian Ocean Territory
|
||||
IQ Iraq
|
||||
IR Iran, Islamic Republic of
|
||||
IS Iceland
|
||||
IT Italy
|
||||
JE Jersey
|
||||
JM Jamaica
|
||||
JO Jordan
|
||||
JP Japan
|
||||
KE Kenya
|
||||
KG Kyrgyzstan
|
||||
KH Cambodia
|
||||
KI Kiribati
|
||||
KM Comoros
|
||||
KN Saint Kitts and Nevis
|
||||
KP Korea, Democratic People's Republic of
|
||||
KR Korea, Republic of
|
||||
KW Kuwait
|
||||
KY Cayman Islands
|
||||
KZ Kazakhstan
|
||||
LA Lao People's Democratic Republic
|
||||
LB Lebanon
|
||||
LC Saint Lucia
|
||||
LI Liechtenstein
|
||||
LK Sri Lanka
|
||||
LR Liberia
|
||||
LS Lesotho
|
||||
LT Lithuania
|
||||
LU Luxembourg
|
||||
LV Latvia
|
||||
LY Libya
|
||||
MA Morocco
|
||||
MC Monaco
|
||||
MD Moldova, Republic of
|
||||
ME Montenegro
|
||||
MF Saint Martin (French part)
|
||||
MG Madagascar
|
||||
MH Marshall Islands
|
||||
MK North Macedonia
|
||||
ML Mali
|
||||
MM Myanmar
|
||||
MN Mongolia
|
||||
MO Macao
|
||||
MP Northern Mariana Islands
|
||||
MQ Martinique
|
||||
MR Mauritania
|
||||
MS Montserrat
|
||||
MT Malta
|
||||
MU Mauritius
|
||||
MV Maldives
|
||||
MW Malawi
|
||||
MX Mexico
|
||||
MY Malaysia
|
||||
MZ Mozambique
|
||||
NA Namibia
|
||||
NC New Caledonia
|
||||
NE Niger
|
||||
NF Norfolk Island
|
||||
NG Nigeria
|
||||
NI Nicaragua
|
||||
NL Netherlands
|
||||
NO Norway
|
||||
NP Nepal
|
||||
NR Nauru
|
||||
NU Niue
|
||||
NZ New Zealand
|
||||
OM Oman
|
||||
PA Panama
|
||||
PE Peru
|
||||
PF French Polynesia
|
||||
PG Papua New Guinea
|
||||
PH Philippines
|
||||
PK Pakistan
|
||||
PL Poland
|
||||
PM Saint Pierre and Miquelon
|
||||
PN Pitcairn
|
||||
PR Puerto Rico
|
||||
PS Palestine, State of
|
||||
PT Portugal
|
||||
PW Palau
|
||||
PY Paraguay
|
||||
QA Qatar
|
||||
RE Réunion
|
||||
RO Romania
|
||||
RS Serbia
|
||||
RU Russian Federation
|
||||
RW Rwanda
|
||||
SA Saudi Arabia
|
||||
SB Solomon Islands
|
||||
SC Seychelles
|
||||
SD Sudan
|
||||
SE Sweden
|
||||
SG Singapore
|
||||
SH Saint Helena, Ascension and Tristan da Cunha
|
||||
SI Slovenia
|
||||
SJ Svalbard and Jan Mayen
|
||||
SK Slovakia
|
||||
SL Sierra Leone
|
||||
SM San Marino
|
||||
SN Senegal
|
||||
SO Somalia
|
||||
SR Suriname
|
||||
SS South Sudan
|
||||
ST Sao Tome and Principe
|
||||
SV El Salvador
|
||||
SX Sint Maarten (Dutch part)
|
||||
SY Syrian Arab Republic
|
||||
SZ Eswatini
|
||||
TC Turks and Caicos Islands
|
||||
TD Chad
|
||||
TF French Southern Territories
|
||||
TG Togo
|
||||
TH Thailand
|
||||
TJ Tajikistan
|
||||
TK Tokelau
|
||||
TL Timor-Leste
|
||||
TM Turkmenistan
|
||||
TN Tunisia
|
||||
TO Tonga
|
||||
TR Türkiye
|
||||
TT Trinidad and Tobago
|
||||
TV Tuvalu
|
||||
TW Taiwan, Province of China
|
||||
TZ Tanzania, United Republic of
|
||||
UA Ukraine
|
||||
UG Uganda
|
||||
UM United States Minor Outlying Islands
|
||||
US United States
|
||||
UY Uruguay
|
||||
UZ Uzbekistan
|
||||
VA Holy See (Vatican City State)
|
||||
VC Saint Vincent and the Grenadines
|
||||
VE Venezuela, Bolivarian Republic of
|
||||
VG Virgin Islands, British
|
||||
VI Virgin Islands, U.S.
|
||||
VN Viet Nam
|
||||
VU Vanuatu
|
||||
WF Wallis and Futuna
|
||||
WS Samoa
|
||||
XK Kosovo
|
||||
YE Yemen
|
||||
YT Mayotte
|
||||
ZA South Africa
|
||||
ZM Zambia
|
||||
ZW Zimbabwe
|
||||
|
@@ -28,6 +28,7 @@ use std::time::Duration;
|
||||
use base64::Engine as _;
|
||||
use base64::engine::general_purpose::STANDARD as BASE64;
|
||||
use keyring_core::Entry;
|
||||
use proton_auth_rs::{KeyringStore, SecretStore};
|
||||
use proton_drive_rs::{KeySalt, ProtonDriveClient};
|
||||
use proton_sdk::account::KeyPassphrases;
|
||||
use proton_sdk::api::{HumanVerification, HumanVerificationCredential};
|
||||
@@ -125,82 +126,28 @@ fn client_config() -> ProtonClientConfiguration {
|
||||
|
||||
/// Run `op` on the session's keyring entry.
|
||||
fn with_keyring<T>(op: impl Fn(&Entry) -> keyring_core::Result<T>) -> Result<T> {
|
||||
with_keyring_entry(KEYRING_SERVICE, KEYRING_USER, op)
|
||||
Ok(keyring().with_entry(KEYRING_USER, op)?)
|
||||
}
|
||||
|
||||
/// Run `op` on the entry `service`/`user`, reconnecting once if the Secret
|
||||
/// Service fails the call.
|
||||
/// The process's keyring, connected on first use.
|
||||
///
|
||||
/// The store holds one D-Bus connection and one Secret Service session for the
|
||||
/// whole process. The session lives in the provider's memory: once the provider
|
||||
/// restarts (oo7's unit restarts it on failure, and both oo7 and gnome-keyring
|
||||
/// can be `--replace`d), every read and write on the old session fails with
|
||||
/// `NoSession`, for as long as this process runs. A daemon then keeps refreshed
|
||||
/// tokens only in memory, and a cold boot loses them (`docs/BUGS.md` B285). A
|
||||
/// platform failure therefore drops the store, and the call is made once more
|
||||
/// on a new one. A locked keyring, a dismissed prompt or a missing entry is
|
||||
/// not the connection's fault and comes back as it is.
|
||||
fn with_keyring_entry<T>(
|
||||
service: &str,
|
||||
user: &str,
|
||||
op: impl Fn(&Entry) -> keyring_core::Result<T>,
|
||||
) -> Result<T> {
|
||||
let store = keyring_store()?;
|
||||
match op(&Entry::new(service, user)?) {
|
||||
Err(keyring_core::Error::PlatformFailure(e)) => {
|
||||
tracing::warn!(
|
||||
error = %e,
|
||||
"the Secret Service failed this process's connection; reconnecting"
|
||||
);
|
||||
drop_keyring_store(&store);
|
||||
keyring_store()?;
|
||||
Ok(op(&Entry::new(service, user)?)?)
|
||||
/// One connection for the whole process; when the Secret Service fails it
|
||||
/// (a restarted provider forgets the session, `docs/BUGS.md` B285), the call
|
||||
/// reconnects and is made once more. A changed session replaces its item
|
||||
/// instead of editing it (B291). Both live in `proton-auth-rs`.
|
||||
fn keyring() -> &'static KeyringStore {
|
||||
static STORE: std::sync::OnceLock<KeyringStore> = std::sync::OnceLock::new();
|
||||
STORE.get_or_init(|| {
|
||||
#[cfg(not(test))]
|
||||
{
|
||||
KeyringStore::new(KEYRING_SERVICE)
|
||||
}
|
||||
result => Ok(result?),
|
||||
}
|
||||
}
|
||||
|
||||
/// Held while the default store is looked at and replaced, so that threads
|
||||
/// failing at the same time drop the broken store once and share its
|
||||
/// replacement.
|
||||
static KEYRING_STORE: parking_lot::Mutex<()> = parking_lot::Mutex::new(());
|
||||
|
||||
/// The process's Secret Service store, connected now if there is none.
|
||||
///
|
||||
/// Connected lazily rather than once at startup so a session bus that was not
|
||||
/// up yet on the first attempt is tried again on the next one.
|
||||
fn keyring_store() -> Result<Arc<keyring_core::CredentialStore>> {
|
||||
let _swap = KEYRING_STORE.lock();
|
||||
if let Some(store) = keyring_core::get_default_store() {
|
||||
return Ok(store);
|
||||
}
|
||||
let store = connect_keyring_store()?;
|
||||
keyring_core::set_default_store(Arc::clone(&store));
|
||||
Ok(store)
|
||||
}
|
||||
|
||||
/// Forget `failed`, unless another thread has already replaced it.
|
||||
fn drop_keyring_store(failed: &Arc<keyring_core::CredentialStore>) {
|
||||
let _swap = KEYRING_STORE.lock();
|
||||
if keyring_core::get_default_store().is_some_and(|store| Arc::ptr_eq(&store, failed)) {
|
||||
keyring_core::unset_default_store();
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(test))]
|
||||
fn connect_keyring_store() -> Result<Arc<keyring_core::CredentialStore>> {
|
||||
Ok(dbus_secret_service_keyring_store::Store::new()?)
|
||||
}
|
||||
|
||||
/// The tests' in-memory store when they set one, so a reconnect finds the
|
||||
/// same entries; the real Secret Service otherwise.
|
||||
#[cfg(test)]
|
||||
fn connect_keyring_store() -> Result<Arc<keyring_core::CredentialStore>> {
|
||||
tests::KEYRING_CONNECTS.fetch_add(1, Ordering::SeqCst);
|
||||
match tests::MOCK_STORE.lock().clone() {
|
||||
Some(store) => Ok(store),
|
||||
None => Ok(dbus_secret_service_keyring_store::Store::new()?),
|
||||
}
|
||||
#[cfg(test)]
|
||||
{
|
||||
KeyringStore::with_connector(KEYRING_SERVICE, Arc::new(tests::connect_keyring_store))
|
||||
.replace_items(|| tests::MOCK_STORE.lock().is_none())
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/// What the user answered when asked for the mailbox password.
|
||||
@@ -490,9 +437,25 @@ fn classify_verification_gate(e: ProtonError) -> Error {
|
||||
}
|
||||
}
|
||||
|
||||
/// Save `stored` to the keyring.
|
||||
///
|
||||
/// Save the session. An existing entry is replaced by a new item rather than
|
||||
/// edited, because oo7 before 0.7.0 keeps an edit only in memory and a reboot
|
||||
/// brings the spent refresh token back (`docs/BUGS.md` B291).
|
||||
fn write_stored(stored: &StoredSession) -> Result<()> {
|
||||
let json = Zeroizing::new(serde_json::to_string(stored)?);
|
||||
with_keyring(|entry| entry.set_password(&json))
|
||||
Ok(keyring().set(KEYRING_USER, &json)?)
|
||||
}
|
||||
|
||||
/// A short, one-way tag for a refresh token, for the log: enough to tell
|
||||
/// whether the token a start finds is the one the last save wrote, and
|
||||
/// nothing that helps anyone use it.
|
||||
fn fingerprint(token: &str) -> String {
|
||||
use sha2::{Digest, Sha256};
|
||||
Sha256::digest(token.as_bytes())[..4]
|
||||
.iter()
|
||||
.map(|b| format!("{b:02x}"))
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Load the persisted session blob, or `Error::NotLoggedIn` if absent.
|
||||
@@ -703,6 +666,10 @@ fn resume_stored(stored: &StoredSession) -> Result<ProtonApiSession> {
|
||||
resumed.access_token = tokens.access_token.clone();
|
||||
resumed.refresh_token = tokens.refresh_token.clone();
|
||||
}
|
||||
tracing::info!(
|
||||
refresh = %fingerprint(&resumed.refresh_token),
|
||||
"resuming the stored session"
|
||||
);
|
||||
let session = ProtonApiSession::resume(client_config(), resumed.to_params())?;
|
||||
let sink = register_refresh_handler(&session, stored.refresh_token.clone());
|
||||
if let Some(tokens) = unsaved {
|
||||
@@ -1082,8 +1049,11 @@ impl TokenSink {
|
||||
) {
|
||||
Rotation::Taken => {
|
||||
write_stored(&stored)?;
|
||||
tracing::info!(
|
||||
refresh = %fingerprint(&tokens.refresh_token),
|
||||
"successfully auto-persisted refreshed tokens in keyring"
|
||||
);
|
||||
state.stored_refresh = tokens.refresh_token;
|
||||
tracing::info!("successfully auto-persisted refreshed tokens in keyring");
|
||||
}
|
||||
Rotation::MovedOn => {
|
||||
tracing::info!(
|
||||
@@ -1280,9 +1250,30 @@ mod tests {
|
||||
let store: Arc<keyring_core::CredentialStore> = keyring_core::mock::Store::new().unwrap();
|
||||
*MOCK_STORE.lock() = Some(Arc::clone(&store));
|
||||
keyring_core::set_default_store(store);
|
||||
keyring().disconnect();
|
||||
turn
|
||||
}
|
||||
|
||||
/// The tests' in-memory store when they set one, so a reconnect finds the
|
||||
/// same entries; the real Secret Service otherwise.
|
||||
pub(super) fn connect_keyring_store() -> keyring_core::Result<Arc<keyring_core::CredentialStore>>
|
||||
{
|
||||
KEYRING_CONNECTS.fetch_add(1, Ordering::SeqCst);
|
||||
match MOCK_STORE.lock().clone() {
|
||||
Some(store) => Ok(store),
|
||||
None => Ok(dbus_secret_service_keyring_store::Store::new()?),
|
||||
}
|
||||
}
|
||||
|
||||
/// Run `op` on the entry `service`/`user` of the real Secret Service.
|
||||
fn with_keyring_entry<T>(
|
||||
store: &KeyringStore,
|
||||
user: &str,
|
||||
op: impl Fn(&Entry) -> keyring_core::Result<T>,
|
||||
) -> Result<T> {
|
||||
Ok(store.with_entry(user, op)?)
|
||||
}
|
||||
|
||||
static KEYRING: parking_lot::Mutex<()> = parking_lot::Mutex::new(());
|
||||
|
||||
/// The in-memory store a reconnect hands out, so it finds the same
|
||||
@@ -1383,7 +1374,8 @@ mod tests {
|
||||
let _turn = KEYRING.lock();
|
||||
*MOCK_STORE.lock() = None;
|
||||
keyring_core::unset_default_store();
|
||||
let (service, user) = ("pdfs-test", "restart");
|
||||
let user = "restart";
|
||||
let service = &KeyringStore::with_connector("pdfs-test", Arc::new(connect_keyring_store));
|
||||
|
||||
with_keyring_entry(service, user, |e| e.set_password("before")).unwrap();
|
||||
let status = std::process::Command::new("sh")
|
||||
@@ -1408,6 +1400,49 @@ mod tests {
|
||||
keyring_core::unset_default_store();
|
||||
}
|
||||
|
||||
/// B291: every save after the first replaces the keyring item, so a
|
||||
/// provider that keeps an edited secret only in memory (oo7 before 0.7.0)
|
||||
/// still has the last one after a restart, and only one item is left.
|
||||
///
|
||||
/// Run like [`real_secret_service_survives_a_provider_restart`], in a
|
||||
/// throwaway session bus only.
|
||||
#[test]
|
||||
#[ignore = "needs a throwaway Secret Service; see real_secret_service_survives_a_provider_restart"]
|
||||
fn real_secret_service_keeps_the_last_save_across_a_provider_restart() {
|
||||
if std::env::var_os("PDFS_SECRET_SERVICE_RESTART_TEST").is_none() {
|
||||
return;
|
||||
}
|
||||
let restart = std::env::var("PDFS_RESTART_PROVIDER").expect("PDFS_RESTART_PROVIDER");
|
||||
let _turn = KEYRING.lock();
|
||||
*MOCK_STORE.lock() = None;
|
||||
keyring_core::unset_default_store();
|
||||
keyring().disconnect();
|
||||
|
||||
for refresh in ["r1", "r2", "r3"] {
|
||||
write_stored(&stored_with(refresh)).unwrap();
|
||||
}
|
||||
let status = std::process::Command::new("sh")
|
||||
.args(["-c", &restart])
|
||||
.status()
|
||||
.unwrap();
|
||||
assert!(status.success(), "restarting the provider failed");
|
||||
std::thread::sleep(Duration::from_secs(1));
|
||||
|
||||
assert_eq!(load().unwrap().refresh_token, "r3");
|
||||
let ss =
|
||||
dbus_secret_service::SecretService::connect(dbus_secret_service::EncryptionType::Plain)
|
||||
.unwrap();
|
||||
let found = ss
|
||||
.search_items(std::collections::HashMap::from([
|
||||
("service", KEYRING_SERVICE),
|
||||
("username", KEYRING_USER),
|
||||
]))
|
||||
.unwrap();
|
||||
assert_eq!(found.unlocked.len() + found.locked.len(), 1);
|
||||
with_keyring(|e| e.delete_credential()).unwrap();
|
||||
keyring_core::unset_default_store();
|
||||
}
|
||||
|
||||
fn stored_with(refresh: &str) -> StoredSession {
|
||||
serde_json::from_str(&blob("").replace(r#""r""#, &format!("{refresh:?}"))).unwrap()
|
||||
}
|
||||
|
||||
@@ -579,6 +579,7 @@ impl ContentCache {
|
||||
// the disk.
|
||||
cache.reseed_totals();
|
||||
cache.import_legacy_pins()?;
|
||||
cache.set_budget(max_bytes);
|
||||
Ok(cache)
|
||||
}
|
||||
|
||||
@@ -1153,16 +1154,18 @@ impl ContentCache {
|
||||
};
|
||||
let mut skipped = 0usize;
|
||||
while running > cap {
|
||||
// Fetch a batch past whatever we have already skipped as exempt.
|
||||
let want = skipped + EVICT_BATCH;
|
||||
let Ok(batch) = self.db.cache_eviction_candidates(kind, want) else {
|
||||
// A whole batch can be pinned. Keep looking until the index has
|
||||
// no entries past the ones we have skipped.
|
||||
let Ok(batch) = self
|
||||
.db
|
||||
.cache_eviction_candidates(kind, EVICT_BATCH, skipped)
|
||||
else {
|
||||
break;
|
||||
};
|
||||
if batch.len() <= skipped {
|
||||
break; // nothing new to consider
|
||||
if batch.is_empty() {
|
||||
break;
|
||||
}
|
||||
let mut evicted_any = false;
|
||||
for (key, size) in batch.into_iter().skip(skipped) {
|
||||
for (key, size) in batch {
|
||||
if running <= cap {
|
||||
break;
|
||||
}
|
||||
@@ -1170,14 +1173,18 @@ impl ContentCache {
|
||||
skipped += 1; // counts toward the total, never a victim
|
||||
continue;
|
||||
}
|
||||
let _ = std::fs::remove_file(dir.join(&key));
|
||||
if let Err(error) = std::fs::remove_file(dir.join(&key))
|
||||
&& error.kind() != std::io::ErrorKind::NotFound
|
||||
{
|
||||
skipped += 1;
|
||||
continue;
|
||||
}
|
||||
let _ = std::fs::remove_file(dir.join(format!("{key}.meta")));
|
||||
let _ = self.db.cache_remove(&key);
|
||||
if self.db.cache_remove(&key).is_err() {
|
||||
skipped += 1;
|
||||
continue;
|
||||
}
|
||||
running = running.saturating_sub(size);
|
||||
evicted_any = true;
|
||||
}
|
||||
if !evicted_any {
|
||||
break; // every remaining candidate is exempt
|
||||
}
|
||||
}
|
||||
// The index is the truth; realign the fast path with it.
|
||||
@@ -1405,7 +1412,7 @@ impl ContentCache {
|
||||
.collect();
|
||||
let content_dir = self.content_dir.clone();
|
||||
// Force pool enforcement ignoring current cap check to free disk space immediately
|
||||
let Ok(list) = self.db.cache_eviction_candidates(KIND_BLOB, 10) else {
|
||||
let Ok(list) = self.db.cache_eviction_candidates(KIND_BLOB, 10, 0) else {
|
||||
return;
|
||||
};
|
||||
for (key, bytes) in list {
|
||||
@@ -1883,13 +1890,13 @@ impl ContentCache {
|
||||
// Pinned blobs (by cache key) are exempt from eviction. Resolves direct
|
||||
// pins plus every descendant of a recursively-pinned folder, hashed into
|
||||
// cache keys to match on-disk filenames.
|
||||
let pinned: HashSet<String> = self
|
||||
.db
|
||||
.pinned_uids()
|
||||
.unwrap_or_default()
|
||||
.iter()
|
||||
.map(|uid| Self::key_str(uid))
|
||||
.collect();
|
||||
let pinned = match self.db.pinned_uids() {
|
||||
Ok(uids) => uids.iter().map(|uid| Self::key_str(uid)).collect(),
|
||||
Err(error) => {
|
||||
tracing::warn!(%error, "reading pins for cache eviction failed");
|
||||
return;
|
||||
}
|
||||
};
|
||||
let content_dir = self.content_dir.clone();
|
||||
self.enforce_pool(KIND_BLOB, &content_dir, Some(&pinned));
|
||||
}
|
||||
@@ -2010,8 +2017,7 @@ impl ContentCache {
|
||||
}
|
||||
|
||||
/// Retune the soft byte cap (`0` = unlimited) at runtime and immediately
|
||||
/// enforce it: blobs and blocks are LRU-evicted back under the new cap (a
|
||||
/// lower cap frees space now; a higher one is a no-op until the next store).
|
||||
/// enforce it across all three pools.
|
||||
/// Called by the daemon when the Settings page changes the cache budget.
|
||||
pub fn set_budget(&self, bytes: u64) {
|
||||
self.max_bytes.store(bytes, Ordering::Relaxed);
|
||||
@@ -2245,19 +2251,50 @@ mod tests {
|
||||
// crash) but the same on-disk cache: reconcile repopulates from disk.
|
||||
let db2 = Arc::new(Db::open_in_memory().unwrap());
|
||||
assert!(db2.cache_entries_by_kind("blob").unwrap().is_empty());
|
||||
let c = ContentCache::open(content, pins, 8, db2.clone()).unwrap();
|
||||
let c = ContentCache::open(content, pins, 0, db2.clone()).unwrap();
|
||||
assert_eq!(db2.cache_entries_by_kind("blob").unwrap().len(), 3);
|
||||
|
||||
// With the index rebuilt, a further store enforces the budget against the
|
||||
// reconciled entries instead of leaking them.
|
||||
c.store(&uid("d"), 1, 4, b"dddd").unwrap();
|
||||
let total: u64 = db2
|
||||
.cache_entries_by_kind("blob")
|
||||
.unwrap()
|
||||
.iter()
|
||||
.map(|(_, s)| s)
|
||||
.sum();
|
||||
assert!(total <= 8, "budget enforced after reconcile, total={total}");
|
||||
assert_eq!(c.usage(), 12);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reopening_trims_all_cache_pools_even_when_the_oldest_batch_is_pinned() {
|
||||
let (c, _dir) = cache();
|
||||
for i in 0..EVICT_BATCH {
|
||||
let u = uid(&format!("pinned-{i}"));
|
||||
c.store(&u, 1, 1, b"p").unwrap();
|
||||
c.add_pin(&u, Path::new("pinned"), false).unwrap();
|
||||
std::fs::File::open(c.blob_path(&u))
|
||||
.unwrap()
|
||||
.set_modified(UNIX_EPOCH)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
let unpinned = uid("unpinned");
|
||||
let payload = [0u8; 64];
|
||||
let size = payload.len() as u64;
|
||||
c.store(&unpinned, 1, size, &payload).unwrap();
|
||||
c.store_block(&unpinned, 1, size, blk(size, 0), &payload)
|
||||
.unwrap();
|
||||
c.store_thumbnail(&unpinned, 1, 1, &payload).unwrap();
|
||||
let recovery = c.recovery_dir.join("recovered.bin");
|
||||
std::fs::write(&recovery, b"recovered write").unwrap();
|
||||
|
||||
let budget = (EVICT_BATCH as u64 * 100).div_ceil(SPLIT_BLOB);
|
||||
let reopened = ContentCache::open(
|
||||
c.content_dir.clone(),
|
||||
c.pins_path.clone(),
|
||||
budget,
|
||||
c.db.clone(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(reopened.usage(), EVICT_BATCH as u64);
|
||||
assert!(!reopened.blob_path(&unpinned).exists());
|
||||
for i in 0..EVICT_BATCH {
|
||||
assert!(reopened.is_cached(&uid(&format!("pinned-{i}")), 1, 1));
|
||||
}
|
||||
assert_eq!(std::fs::read(recovery).unwrap(), b"recovered write");
|
||||
}
|
||||
|
||||
/// An eviction removes the blob, then its tag. A crash in between, or a
|
||||
|
||||
@@ -391,6 +391,27 @@ impl AppConfig {
|
||||
}
|
||||
}
|
||||
|
||||
/// Apply `edit` to the ignore patterns in effect in the config at `path`,
|
||||
/// under the config lock, and return the saved config. A list equal to the
|
||||
/// built-in one is stored as unset, so it follows the built-in list in later
|
||||
/// releases.
|
||||
pub fn change_ignore_patterns_at(
|
||||
path: &Path,
|
||||
edit: impl FnOnce(&mut Vec<String>),
|
||||
) -> Result<AppConfig> {
|
||||
update_config_at(path, |config| {
|
||||
let mut list = config.resolved_ignore_patterns();
|
||||
edit(&mut list);
|
||||
let builtin = list.len() == DEFAULT_IGNORE_PATTERNS.len()
|
||||
&& list
|
||||
.iter()
|
||||
.zip(DEFAULT_IGNORE_PATTERNS)
|
||||
.all(|(a, b)| a == b);
|
||||
config.ignore_patterns = (!builtin).then_some(list);
|
||||
config.clone()
|
||||
})
|
||||
}
|
||||
|
||||
/// Fail when the config file at `path` exists but does not parse, so that
|
||||
/// [`AppDirs::save_config`] never writes over settings it could not read.
|
||||
fn refuse_to_replace_unreadable(path: &Path) -> Result<()> {
|
||||
@@ -407,6 +428,97 @@ fn refuse_to_replace_unreadable(path: &Path) -> Result<()> {
|
||||
}
|
||||
}
|
||||
|
||||
/// [`AppDirs::load_config`] for the file at `path`.
|
||||
fn load_config_at(path: &Path) -> AppConfig {
|
||||
if path.exists() {
|
||||
match std::fs::read_to_string(path)
|
||||
.map_err(Error::from)
|
||||
.and_then(|content| serde_json::from_str::<AppConfig>(&content).map_err(Error::from))
|
||||
{
|
||||
Ok(config) => return config,
|
||||
Err(e) => {
|
||||
// Preserve the original bytes for diagnosis/recovery. In
|
||||
// particular, never replace a truncated config with defaults
|
||||
// and silently lose mount, device, or ignore settings.
|
||||
// `save_config` refuses to write over it for the same reason.
|
||||
tracing::error!(path = %path.display(), error = %e, "config is unreadable; using in-memory defaults without overwriting it");
|
||||
return AppConfig::default();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let default_config = AppConfig::default();
|
||||
if let Err(e) = save_config_at(path, &default_config) {
|
||||
tracing::warn!(path = %path.display(), error = %e, "could not write the default config");
|
||||
}
|
||||
default_config
|
||||
}
|
||||
|
||||
/// [`AppDirs::save_config`] for the file at `path`.
|
||||
fn save_config_at(path: &Path, config: &AppConfig) -> Result<()> {
|
||||
refuse_to_replace_unreadable(path)?;
|
||||
proton_base_rs::atomic::write(path, &serde_json::to_vec_pretty(config)?)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// [`AppDirs::update_config`] for the file at `path`.
|
||||
fn update_config_at<R>(path: &Path, change: impl FnOnce(&mut AppConfig) -> R) -> Result<R> {
|
||||
let _lock = lock_config(path)?;
|
||||
// Refuse before reading: an unreadable file loads as defaults, and the
|
||||
// change must not be applied to those.
|
||||
refuse_to_replace_unreadable(path)?;
|
||||
let mut config = load_config_at(path);
|
||||
let out = change(&mut config);
|
||||
save_config_at(path, &config)?;
|
||||
Ok(out)
|
||||
}
|
||||
|
||||
/// How long [`lock_config`] waits for another writer. A change holds the lock
|
||||
/// for one small read and write; anything longer is a stuck process, and the
|
||||
/// setting is better reported as not saved than waited on forever.
|
||||
const CONFIG_LOCK_WAIT: std::time::Duration = std::time::Duration::from_secs(5);
|
||||
|
||||
/// Take the lock that orders changes to the config file at `path`, held until
|
||||
/// the returned file is dropped.
|
||||
///
|
||||
/// A separate `config.json.lock`, never the config file itself: that file is
|
||||
/// replaced by a rename on every save, so a lock on it would guard a file
|
||||
/// nobody reads any more.
|
||||
fn lock_config(path: &Path) -> Result<std::fs::File> {
|
||||
use std::os::fd::AsRawFd as _;
|
||||
use std::os::unix::fs::OpenOptionsExt as _;
|
||||
if let Some(parent) = path.parent() {
|
||||
std::fs::create_dir_all(parent)?;
|
||||
}
|
||||
let mut name = path.as_os_str().to_owned();
|
||||
name.push(".lock");
|
||||
let file = std::fs::OpenOptions::new()
|
||||
.create(true)
|
||||
.read(true)
|
||||
.write(true)
|
||||
.truncate(false)
|
||||
.mode(0o600)
|
||||
.open(PathBuf::from(name))?;
|
||||
let deadline = std::time::Instant::now() + CONFIG_LOCK_WAIT;
|
||||
loop {
|
||||
// SAFETY: `file` owns the descriptor and outlives the call.
|
||||
if unsafe { libc::flock(file.as_raw_fd(), libc::LOCK_EX | libc::LOCK_NB) } == 0 {
|
||||
return Ok(file);
|
||||
}
|
||||
let e = std::io::Error::last_os_error();
|
||||
if e.raw_os_error() != Some(libc::EWOULDBLOCK) {
|
||||
return Err(Error::Io(e));
|
||||
}
|
||||
if std::time::Instant::now() >= deadline {
|
||||
return Err(Error::Other(format!(
|
||||
"{} is being changed by another process; try again",
|
||||
path.display()
|
||||
)));
|
||||
}
|
||||
std::thread::sleep(std::time::Duration::from_millis(10));
|
||||
}
|
||||
}
|
||||
|
||||
/// Resolved XDG locations for state, cache, and the default mountpoint.
|
||||
pub struct AppDirs {
|
||||
dirs: ProjectDirs,
|
||||
@@ -426,65 +538,40 @@ impl AppDirs {
|
||||
|
||||
/// Load config from disk, creating default if missing.
|
||||
pub fn load_config(&self) -> AppConfig {
|
||||
let path = self.config_path();
|
||||
if path.exists() {
|
||||
match std::fs::read_to_string(&path)
|
||||
.map_err(Error::from)
|
||||
.and_then(|content| {
|
||||
serde_json::from_str::<AppConfig>(&content).map_err(Error::from)
|
||||
}) {
|
||||
Ok(config) => return config,
|
||||
Err(e) => {
|
||||
// Preserve the original bytes for diagnosis/recovery. In
|
||||
// particular, never replace a truncated config with defaults
|
||||
// and silently lose mount, device, or ignore settings.
|
||||
// `save_config` refuses to write over it for the same reason.
|
||||
tracing::error!(path = %path.display(), error = %e, "config is unreadable; using in-memory defaults without overwriting it");
|
||||
return AppConfig::default();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let default_config = AppConfig::default();
|
||||
if let Err(e) = self.save_config(&default_config) {
|
||||
tracing::warn!(path = %path.display(), error = %e, "could not write the default config");
|
||||
}
|
||||
default_config
|
||||
load_config_at(&self.config_path())
|
||||
}
|
||||
|
||||
/// Persist `config` to [`config_path`](Self::config_path), creating the
|
||||
/// config dir if missing. The Settings page calls this after editing the
|
||||
/// cache budget or mountpoint; the daemon re-reads the file on its next mount.
|
||||
/// config dir if missing.
|
||||
///
|
||||
/// Refuses while the file on disk does not parse. Every caller loads,
|
||||
/// changes one field and saves, and [`load_config`](Self::load_config)
|
||||
/// gives defaults for a file it cannot read, so the first change after
|
||||
/// the file was damaged wrote defaults over the mountpoint, the device and
|
||||
/// the ignore rules the user had (`docs/BUGS.md` B223).
|
||||
/// Refuses while the file on disk does not parse: [`load_config`](Self::load_config)
|
||||
/// gives defaults for a file it cannot read, so the first change after the
|
||||
/// file was damaged would write defaults over the mountpoint, the device
|
||||
/// and the ignore rules the user had (`docs/BUGS.md` B223).
|
||||
///
|
||||
/// Writes the whole file. To change a setting, use
|
||||
/// [`update_config`](Self::update_config), which does not lose another
|
||||
/// process's change.
|
||||
pub fn save_config(&self, config: &AppConfig) -> Result<()> {
|
||||
let path = self.config_path();
|
||||
refuse_to_replace_unreadable(&path)?;
|
||||
let parent = path
|
||||
.parent()
|
||||
.ok_or_else(|| Error::Other("configuration path has no parent".into()))?;
|
||||
std::fs::create_dir_all(parent)?;
|
||||
let nonce = std::time::SystemTime::now()
|
||||
.duration_since(std::time::UNIX_EPOCH)
|
||||
.map(|duration| duration.as_nanos())
|
||||
.unwrap_or(0);
|
||||
let tmp = path.with_extension(format!("json.tmp-{}-{nonce}", std::process::id()));
|
||||
use std::os::unix::fs::OpenOptionsExt as _;
|
||||
let mut file = std::fs::OpenOptions::new()
|
||||
.write(true)
|
||||
.create_new(true)
|
||||
.mode(0o600)
|
||||
.open(&tmp)?;
|
||||
use std::io::Write as _;
|
||||
file.write_all(&serde_json::to_vec_pretty(config)?)?;
|
||||
file.sync_all()?;
|
||||
std::fs::rename(&tmp, &path)?;
|
||||
std::fs::File::open(parent)?.sync_all()?;
|
||||
Ok(())
|
||||
save_config_at(&self.config_path(), config)
|
||||
}
|
||||
|
||||
/// Change settings in place: read the file, apply `change`, write it back,
|
||||
/// all under a lock, and return what `change` returned.
|
||||
///
|
||||
/// The app, the tray and the daemon each write the file. Without the lock,
|
||||
/// two of them changing different settings at once both read the old file,
|
||||
/// and the one that wrote last undid the other's change (`docs/BUGS.md`
|
||||
/// B292).
|
||||
pub fn update_config<R>(&self, change: impl FnOnce(&mut AppConfig) -> R) -> Result<R> {
|
||||
update_config_at(&self.config_path(), change)
|
||||
}
|
||||
|
||||
/// Apply `edit` to the ignore patterns in effect for every synced folder
|
||||
/// and save them, returning the saved config. See
|
||||
/// [`change_ignore_patterns_at`].
|
||||
pub fn change_ignore_patterns(&self, edit: impl FnOnce(&mut Vec<String>)) -> Result<AppConfig> {
|
||||
change_ignore_patterns_at(&self.config_path(), edit)
|
||||
}
|
||||
|
||||
/// This machine's id (e.g. ~/.config/proton-drive-linux/machine-id). See
|
||||
@@ -515,15 +602,8 @@ impl AppDirs {
|
||||
use std::io::Read as _;
|
||||
std::fs::File::open("/dev/urandom")?.read_exact(&mut bytes)?;
|
||||
let id: String = bytes.iter().map(|b| format!("{b:02x}")).collect();
|
||||
let parent = path
|
||||
.parent()
|
||||
.ok_or_else(|| Error::Other("machine id path has no parent".into()))?;
|
||||
std::fs::create_dir_all(parent)?;
|
||||
let tmp = path.with_extension(format!("tmp-{}", std::process::id()));
|
||||
std::fs::write(&tmp, format!("{id}\n"))?;
|
||||
std::fs::File::open(&tmp)?.sync_all()?;
|
||||
std::fs::rename(&tmp, &path)?;
|
||||
std::fs::File::open(parent)?.sync_all()?;
|
||||
// Not secret, and other tools may read it; keep it world-readable.
|
||||
proton_base_rs::atomic::write_with_mode(&path, format!("{id}\n").as_bytes(), 0o644)?;
|
||||
Ok(id)
|
||||
}
|
||||
|
||||
@@ -682,6 +762,89 @@ mod tests {
|
||||
std::fs::metadata(p).unwrap().permissions().mode() & 0o777
|
||||
}
|
||||
|
||||
/// Two writers changing different settings at once both keep their change
|
||||
/// (`docs/BUGS.md` B292).
|
||||
#[test]
|
||||
fn concurrent_changes_to_different_settings_are_all_kept() {
|
||||
let dir = std::env::temp_dir().join(format!(
|
||||
"pdfs-cfg-race-{}-{:?}",
|
||||
std::process::id(),
|
||||
std::thread::current().id()
|
||||
));
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
std::fs::create_dir_all(&dir).unwrap();
|
||||
let path = dir.join("config.json");
|
||||
|
||||
let a = {
|
||||
let path = path.clone();
|
||||
std::thread::spawn(move || {
|
||||
for i in 1..=100u64 {
|
||||
update_config_at(&path, |c| c.upload_limit = Some(i)).unwrap();
|
||||
}
|
||||
})
|
||||
};
|
||||
let b = {
|
||||
let path = path.clone();
|
||||
std::thread::spawn(move || {
|
||||
for i in 1..=100u64 {
|
||||
update_config_at(&path, |c| c.download_limit = Some(i)).unwrap();
|
||||
}
|
||||
})
|
||||
};
|
||||
a.join().unwrap();
|
||||
b.join().unwrap();
|
||||
|
||||
let config = load_config_at(&path);
|
||||
assert_eq!(config.upload_limit, Some(100));
|
||||
assert_eq!(config.download_limit, Some(100));
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ignore_patterns_back_at_the_built_in_list_are_stored_as_unset() {
|
||||
let dir = std::env::temp_dir().join(format!(
|
||||
"pdfs-cfg-ignore-{}-{:?}",
|
||||
std::process::id(),
|
||||
std::thread::current().id()
|
||||
));
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
std::fs::create_dir_all(&dir).unwrap();
|
||||
let path = dir.join("config.json");
|
||||
|
||||
let config = change_ignore_patterns_at(&path, |list| list.push("*.db".into())).unwrap();
|
||||
assert_eq!(
|
||||
config.ignore_patterns.as_ref().unwrap().last().unwrap(),
|
||||
"*.db"
|
||||
);
|
||||
let config = change_ignore_patterns_at(&path, |list| list.retain(|p| p != "*.db")).unwrap();
|
||||
assert_eq!(config.ignore_patterns, None);
|
||||
assert_eq!(load_config_at(&path).ignore_patterns, None);
|
||||
// An empty list is a choice, not the built-in one.
|
||||
let config = change_ignore_patterns_at(&path, Vec::clear).unwrap();
|
||||
assert_eq!(config.ignore_patterns, Some(Vec::new()));
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_change_is_never_applied_over_an_unreadable_config() {
|
||||
let dir = std::env::temp_dir().join(format!(
|
||||
"pdfs-cfg-update-guard-{}-{:?}",
|
||||
std::process::id(),
|
||||
std::thread::current().id()
|
||||
));
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
std::fs::create_dir_all(&dir).unwrap();
|
||||
let path = dir.join("config.json");
|
||||
std::fs::write(&path, br#"{"mountpoint": "/home/me/Pro"#).unwrap();
|
||||
|
||||
assert!(update_config_at(&path, |c| c.tray_hidden = true).is_err());
|
||||
assert_eq!(
|
||||
std::fs::read(&path).unwrap(),
|
||||
br#"{"mountpoint": "/home/me/Pro"#
|
||||
);
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
/// A damaged config must not be replaced by defaults the next time a
|
||||
/// setting changes (`docs/BUGS.md` B223).
|
||||
#[test]
|
||||
|
||||
@@ -44,14 +44,20 @@ pub enum Request {
|
||||
/// Report mount status (account, mountpoint, pin count).
|
||||
Status,
|
||||
/// Pin a file (path relative to the mountpoint, or absolute under it).
|
||||
Pin { path: String },
|
||||
Pin {
|
||||
path: String,
|
||||
},
|
||||
/// Unpin a file, evicting its cached content.
|
||||
Unpin { path: String },
|
||||
Unpin {
|
||||
path: String,
|
||||
},
|
||||
/// List pinned files.
|
||||
ListPins,
|
||||
/// List a directory for the in-app file browser. `path` is
|
||||
/// mountpoint-relative (empty or "." = the mount root).
|
||||
ListDir { path: String },
|
||||
ListDir {
|
||||
path: String,
|
||||
},
|
||||
/// Fetch a page of the photos timeline, newest first. Returns metadata only:
|
||||
/// a thumbnail path comes back only for photos already in the cache, so the
|
||||
/// reply never waits on the network. Front-ends ask for the thumbnails they
|
||||
@@ -83,7 +89,15 @@ pub enum Request {
|
||||
/// live photo and its clip. Replies with [`Response::Photos`], holding one
|
||||
/// item per file in server order; a photo that stands alone comes back as a
|
||||
/// single item. The lightbox uses it to switch between a shot's files.
|
||||
PhotoGroup { uid: String },
|
||||
PhotoGroup {
|
||||
uid: String,
|
||||
},
|
||||
/// Check the cached photo or its membership in the viewer's open album.
|
||||
PhotoPresence {
|
||||
uid: String,
|
||||
#[serde(default)]
|
||||
album: Option<String>,
|
||||
},
|
||||
/// The months the timeline spans (newest first, with per-month counts) so a
|
||||
/// front-end can build a date scrubber without paging the whole library.
|
||||
/// `kind` scopes the counts to one tab when set.
|
||||
@@ -94,7 +108,9 @@ pub enum Request {
|
||||
/// Photos taken on today's date in earlier years, newest first, at most
|
||||
/// `limit` of them — the "On this day" strip above the timeline. Replies
|
||||
/// with [`Response::Photos`]; a front-end groups them by year itself.
|
||||
PhotosOnThisDay { limit: usize },
|
||||
PhotosOnThisDay {
|
||||
limit: usize,
|
||||
},
|
||||
/// Sets of photos that are byte-identical copies of each other, going by
|
||||
/// the server's content hash. Replies with [`Response::PhotoDuplicates`].
|
||||
PhotoDuplicates,
|
||||
@@ -118,7 +134,9 @@ pub enum Request {
|
||||
},
|
||||
/// Every photo taken in one town with where exactly it was taken, for the
|
||||
/// map's close-up. Replies with [`Response::PhotoLocations`].
|
||||
PlaceLocations { id: u32 },
|
||||
PlaceLocations {
|
||||
id: u32,
|
||||
},
|
||||
/// List the account's photo albums, newest activity first, including the
|
||||
/// albums other people share with us. Metadata only — an album's cover
|
||||
/// thumbnail is fetched with [`Request::PhotoThumbs`] like any other photo.
|
||||
@@ -134,9 +152,14 @@ pub enum Request {
|
||||
limit: usize,
|
||||
},
|
||||
/// Create an album named `name`. Replies with [`Response::AlbumCreated`].
|
||||
CreateAlbum { name: String },
|
||||
CreateAlbum {
|
||||
name: String,
|
||||
},
|
||||
/// Rename the album `uid`. Replies with [`Response::Ok`].
|
||||
RenameAlbum { uid: String, name: String },
|
||||
RenameAlbum {
|
||||
uid: String,
|
||||
name: String,
|
||||
},
|
||||
/// Delete the album `uid`. Its photos stay in the timeline; with
|
||||
/// `delete_photos` set, photos that exist only in the album (saved from a
|
||||
/// shared album) are deleted with it, which the server otherwise refuses.
|
||||
@@ -148,14 +171,22 @@ pub enum Request {
|
||||
},
|
||||
/// Add timeline photos to the album `uid`. Replies with
|
||||
/// [`Response::AlbumChanged`].
|
||||
AddToAlbum { uid: String, photos: Vec<String> },
|
||||
AddToAlbum {
|
||||
uid: String,
|
||||
photos: Vec<String>,
|
||||
},
|
||||
/// Take photos out of the album `uid`. They stay in the timeline: this is
|
||||
/// not a trash. Replies with [`Response::AlbumChanged`].
|
||||
RemoveFromAlbum { uid: String, photos: Vec<String> },
|
||||
RemoveFromAlbum {
|
||||
uid: String,
|
||||
photos: Vec<String>,
|
||||
},
|
||||
/// Fetch thumbnails for the given photo uids, downloading the ones not
|
||||
/// already cached (one batched round-trip) and replying with their on-disk
|
||||
/// paths. Keep the batch small — it is served on demand, as tiles scroll in.
|
||||
PhotoThumbs { uids: Vec<String> },
|
||||
PhotoThumbs {
|
||||
uids: Vec<String>,
|
||||
},
|
||||
/// Trash photos by node uid, answered with [`Response::Trashed`].
|
||||
///
|
||||
/// Uid-addressed rather than path-addressed because the photos volume is not
|
||||
@@ -190,11 +221,15 @@ pub enum Request {
|
||||
ReserveFileThumbGeneration,
|
||||
/// Stop ordinary-file thumbnail work belonging to older listings. Photos
|
||||
/// timeline work and an explicit recursive build are deliberately separate.
|
||||
CancelFileThumbs { generation: u64 },
|
||||
CancelFileThumbs {
|
||||
generation: u64,
|
||||
},
|
||||
/// Start building local thumbnails for every supported image below `path`.
|
||||
/// The request returns immediately; progress is read with
|
||||
/// [`Request::ThumbnailBuildStatus`].
|
||||
StartThumbnailBuild { path: String },
|
||||
StartThumbnailBuild {
|
||||
path: String,
|
||||
},
|
||||
/// Stop the current recursive ordinary-file thumbnail build, if any.
|
||||
CancelThumbnailBuild,
|
||||
/// Read progress for the recursive ordinary-file thumbnail build.
|
||||
@@ -206,7 +241,31 @@ pub enum Request {
|
||||
/// is how a front-end knows when the refreshed timeline is worth re-reading.
|
||||
PhotosRefreshStatus,
|
||||
/// Download a photo's full content into the cache; replies with its path.
|
||||
OpenPhoto { uid: String },
|
||||
OpenPhoto {
|
||||
uid: String,
|
||||
},
|
||||
/// Open a revision for playback in the local viewer.
|
||||
OpenGalleryVideo {
|
||||
uid: String,
|
||||
#[serde(default)]
|
||||
private: bool,
|
||||
},
|
||||
OpenGalleryImage {
|
||||
uid: String,
|
||||
#[serde(default)]
|
||||
private: bool,
|
||||
},
|
||||
CloseGalleryVideo {
|
||||
token: String,
|
||||
},
|
||||
GalleryThumbnail {
|
||||
uid: String,
|
||||
#[serde(default)]
|
||||
private: bool,
|
||||
},
|
||||
DriveGallery {
|
||||
action: GalleryAction,
|
||||
},
|
||||
/// Add or remove Proton's `Favorite` tag on a photo. Replies with
|
||||
/// [`Response::Ok`].
|
||||
///
|
||||
@@ -214,7 +273,10 @@ pub enum Request {
|
||||
/// one shared with us, or one that lives only in an album — needs it
|
||||
/// re-encrypted for our timeline, which the SDK does not implement yet; the
|
||||
/// daemon reports that as an error rather than silently doing nothing.
|
||||
SetPhotoFavorite { uid: String, favorite: bool },
|
||||
SetPhotoFavorite {
|
||||
uid: String,
|
||||
favorite: bool,
|
||||
},
|
||||
/// Import Google Photos **Takeout** archives into Proton Photos.
|
||||
///
|
||||
/// `archives` are absolute paths to the export's `.zip` parts on the
|
||||
@@ -326,7 +388,10 @@ pub enum Request {
|
||||
/// Search the daemon's index of *local* (non-Drive) files on this machine.
|
||||
/// Independent of [`Request::Search`] so a front-end can fire both at once and
|
||||
/// render whichever lands first. Replies with [`Response::LocalResults`].
|
||||
SearchLocal { query: String, limit: usize },
|
||||
SearchLocal {
|
||||
query: String,
|
||||
limit: usize,
|
||||
},
|
||||
/// Search both the Drive metadata index and the local-file index in one
|
||||
/// round-trip. This is the preferred prompt API; the two legacy search
|
||||
/// requests remain available for older clients. `limit` applies to each
|
||||
@@ -342,30 +407,48 @@ pub enum Request {
|
||||
},
|
||||
/// Rename a file or folder. `path` is mountpoint-relative; `new_name` is a
|
||||
/// single path component (no separators). Replies with [`Response::Ok`].
|
||||
Rename { path: String, new_name: String },
|
||||
Rename {
|
||||
path: String,
|
||||
new_name: String,
|
||||
},
|
||||
/// Move a file or folder into a new parent folder. Both `path` and
|
||||
/// `new_parent` are mountpoint-relative, or both absolute local paths; two
|
||||
/// absolute paths may lie in different locations (My files, an on-demand
|
||||
/// or a mirror synced folder), and the move is still made on Proton Drive
|
||||
/// without transferring content. Replies with [`Response::Ok`].
|
||||
Move { path: String, new_parent: String },
|
||||
Move {
|
||||
path: String,
|
||||
new_parent: String,
|
||||
},
|
||||
/// Copy a file or folder into a folder on Proton Drive, without
|
||||
/// downloading or uploading it. Both `path` and `new_parent` are
|
||||
/// mountpoint-relative, or absolute paths inside My files. A name already
|
||||
/// taken in `new_parent` gets the next free ` (n)` suffix. Replies with
|
||||
/// [`Response::Ok`].
|
||||
Copy { path: String, new_parent: String },
|
||||
Copy {
|
||||
path: String,
|
||||
new_parent: String,
|
||||
},
|
||||
/// Ask Proton Drive how much the folder at mountpoint-relative `path`
|
||||
/// holds. Replies with [`Response::FolderSize`].
|
||||
FolderSize { path: String },
|
||||
FolderSize {
|
||||
path: String,
|
||||
},
|
||||
/// The by-uid twin of [`Request::FolderSize`].
|
||||
FolderSizeByUid { uid: String },
|
||||
FolderSizeByUid {
|
||||
uid: String,
|
||||
},
|
||||
/// Trash a file or folder. `path` is mountpoint-relative. Replies with
|
||||
/// [`Response::Ok`].
|
||||
Delete { path: String },
|
||||
Delete {
|
||||
path: String,
|
||||
},
|
||||
/// Create a new folder named `name` under the mountpoint-relative `parent`.
|
||||
/// Replies with [`Response::Ok`].
|
||||
CreateFolder { parent: String, name: String },
|
||||
CreateFolder {
|
||||
parent: String,
|
||||
name: String,
|
||||
},
|
||||
// There is deliberately no bytes-carrying single-file upload: it was
|
||||
// `UploadFile { parent, name, bytes }`, and it OOMed on anything large for
|
||||
// the reason described on `UploadPhoto`. `UploadPaths` covers the same case
|
||||
@@ -388,11 +471,16 @@ pub enum Request {
|
||||
/// Retune the on-disk cache's soft byte cap at runtime (`0` = unlimited) and
|
||||
/// persist it to config so the next mount keeps it. Replies with
|
||||
/// [`Response::Ok`].
|
||||
SetCacheBudget { bytes: u64 },
|
||||
SetCacheBudget {
|
||||
bytes: u64,
|
||||
},
|
||||
/// Cap uploads and downloads at these bytes per second (`0` = no cap),
|
||||
/// live for running transfers, and persist both to config so the next
|
||||
/// mount keeps them. Replies with [`Response::Ok`].
|
||||
SetBandwidthLimits { upload: u64, download: u64 },
|
||||
SetBandwidthLimits {
|
||||
upload: u64,
|
||||
download: u64,
|
||||
},
|
||||
/// Report on the health of the metadata database and content cache: sizes,
|
||||
/// row counts, and — when `deep` — SQLite's own integrity check. Replies
|
||||
/// with [`Response::CacheReport`].
|
||||
@@ -429,10 +517,14 @@ pub enum Request {
|
||||
ListTrash,
|
||||
/// Restore trashed nodes, by uid, to the folders they were trashed from.
|
||||
/// Replies with [`Response::Ok`].
|
||||
Restore { uids: Vec<String> },
|
||||
Restore {
|
||||
uids: Vec<String>,
|
||||
},
|
||||
/// Permanently delete trashed nodes by uid. Irreversible: the content is
|
||||
/// gone from Proton Drive, not moved. Replies with [`Response::Ok`].
|
||||
DeleteForever { uids: Vec<String> },
|
||||
DeleteForever {
|
||||
uids: Vec<String>,
|
||||
},
|
||||
/// Permanently delete everything in the trash. Irreversible.
|
||||
/// Replies with [`Response::Ok`].
|
||||
EmptyTrash,
|
||||
@@ -443,7 +535,9 @@ pub enum Request {
|
||||
/// only notices another client's changes when its TTL lapses, so a user who
|
||||
/// knows the cache is stale needs a way to say so. Cheap and idempotent —
|
||||
/// it invalidates, it does not fetch.
|
||||
Refresh { scope: RefreshScope },
|
||||
Refresh {
|
||||
scope: RefreshScope,
|
||||
},
|
||||
|
||||
// ---- locations --------------------------------------------------------
|
||||
/// List every local Proton Drive location. Replies with
|
||||
@@ -454,26 +548,37 @@ pub enum Request {
|
||||
/// List the account's registered devices. Replies with [`Response::Devices`].
|
||||
ListDevices,
|
||||
/// Rename a device by its uid. Replies with [`Response::Ok`].
|
||||
RenameDevice { uid: String, name: String },
|
||||
RenameDevice {
|
||||
uid: String,
|
||||
name: String,
|
||||
},
|
||||
/// Delete (deregister) a device by its uid. Replies with [`Response::Ok`].
|
||||
DeleteDevice { uid: String },
|
||||
DeleteDevice {
|
||||
uid: String,
|
||||
},
|
||||
/// Adopt an existing device as this machine's, pinning its uid in
|
||||
/// `config.json` so a hostname change or reinstall re-attaches to it instead
|
||||
/// of registering a duplicate. `uid: None` clears the pin.
|
||||
/// Replies with [`Response::Ok`].
|
||||
AdoptDevice { uid: Option<String> },
|
||||
AdoptDevice {
|
||||
uid: Option<String>,
|
||||
},
|
||||
/// Move every folder another device backs up into this machine's own
|
||||
/// device, as server-side moves on the main volume. The other device stays
|
||||
/// registered, without those folders. Sync folders here that already track
|
||||
/// one of them follow it to its new share. Nothing is downloaded: the moved
|
||||
/// folders are then offered by [`Request::ListRestorableFolders`].
|
||||
/// Replies with [`Response::Ok`].
|
||||
MigrateDevice { uid: String },
|
||||
MigrateDevice {
|
||||
uid: String,
|
||||
},
|
||||
|
||||
// ---- device folder sync ----------------------------------
|
||||
/// Add a local folder to this machine's device, uploading its tree and
|
||||
/// registering the device on first use. Replies with [`Response::Ok`].
|
||||
AddSyncFolder { local_path: String },
|
||||
AddSyncFolder {
|
||||
local_path: String,
|
||||
},
|
||||
/// Keep a real local directory in step with an existing folder in My files.
|
||||
/// First sync unions one-sided files and preserves differing versions.
|
||||
/// Replies with [`Response::Ok`]; no device backup is created.
|
||||
@@ -485,42 +590,65 @@ pub enum Request {
|
||||
ListSyncFolders,
|
||||
/// Remove a synced folder by id; `delete_remote` also trashes its cloud copy.
|
||||
/// Replies with [`Response::Ok`].
|
||||
RemoveSyncFolder { id: i64, delete_remote: bool },
|
||||
RemoveSyncFolder {
|
||||
id: i64,
|
||||
delete_remote: bool,
|
||||
},
|
||||
/// Switch a synced folder between `mirror` and `ondemand` (Phase 3). Replies
|
||||
/// with [`Response::Ok`].
|
||||
SetSyncFolderMode { id: i64, mode: String },
|
||||
SetSyncFolderMode {
|
||||
id: i64,
|
||||
mode: String,
|
||||
},
|
||||
/// Pause or resume one mirror folder's reconcile, independent of the
|
||||
/// global pause. Persisted until resumed. Replies with [`Response::Ok`].
|
||||
SetSyncFolderPaused { id: i64, paused: bool },
|
||||
SetSyncFolderPaused {
|
||||
id: i64,
|
||||
paused: bool,
|
||||
},
|
||||
/// Forget what a mirror folder synced before, so its next pass compares
|
||||
/// both sides afresh: what is on one side only is copied to the other, and
|
||||
/// a file that differs keeps both versions. Nothing is deleted. Replies
|
||||
/// with [`Response::Ok`].
|
||||
ResetSyncFolder { id: i64 },
|
||||
ResetSyncFolder {
|
||||
id: i64,
|
||||
},
|
||||
/// Force a reconcile pass: one folder by id, or all when `id` is `None`.
|
||||
/// Replies with [`Response::Ok`].
|
||||
SyncNow { id: Option<i64> },
|
||||
SyncNow {
|
||||
id: Option<i64>,
|
||||
},
|
||||
/// Pause or resume syncing: queued uploads and changes stop draining and
|
||||
/// mirror folders stop reconciling, while reads through the mount keep
|
||||
/// working. `until` is the Unix second a pause ends by itself; `None`
|
||||
/// pauses until resumed. Ignored when resuming. Replies with
|
||||
/// [`Response::Ok`].
|
||||
SetSyncPaused { paused: bool, until: Option<i64> },
|
||||
SetSyncPaused {
|
||||
paused: bool,
|
||||
until: Option<i64>,
|
||||
},
|
||||
/// List the queue of uploads and changes not yet on the remote. Replies
|
||||
/// with [`Response::PendingOps`].
|
||||
ListPendingOps,
|
||||
/// Retry a backed-off queued op now instead of waiting out its backoff;
|
||||
/// every failed op when `id` is `None`. Replies with [`Response::Ok`].
|
||||
RetryPendingOp { id: Option<i64> },
|
||||
RetryPendingOp {
|
||||
id: Option<i64>,
|
||||
},
|
||||
/// Copy the content of a queued upload (`id` from
|
||||
/// [`Request::ListPendingOps`]) to `dest`, an absolute path that must not
|
||||
/// exist yet. The op stays queued. Replies with [`Response::Ok`].
|
||||
ExportPendingOp { id: i64, dest: String },
|
||||
ExportPendingOp {
|
||||
id: i64,
|
||||
dest: String,
|
||||
},
|
||||
/// Drop a queued change (`id` from [`Request::ListPendingOps`]) and undo
|
||||
/// it locally: a node made here goes, a node Drive has goes back to what
|
||||
/// Drive has, along with every other change queued on it. Its content is
|
||||
/// lost unless it was exported first. Replies with [`Response::Ok`].
|
||||
DiscardPendingOp { id: i64 },
|
||||
DiscardPendingOp {
|
||||
id: i64,
|
||||
},
|
||||
/// List the `(sync-conflict …)` copies under My Files and in synced
|
||||
/// folders. Replies with
|
||||
/// [`Response::Conflicts`].
|
||||
@@ -529,18 +657,25 @@ pub enum Request {
|
||||
/// copy in a synced folder).
|
||||
/// Everything removed goes to the Proton trash. Replies with
|
||||
/// [`Response::Ok`].
|
||||
ResolveConflict { path: String, keep: ConflictKeep },
|
||||
ResolveConflict {
|
||||
path: String,
|
||||
keep: ConflictKeep,
|
||||
},
|
||||
/// List the folders under this machine's device that can be synced here,
|
||||
/// each with a proposed local path. Replies with
|
||||
/// [`Response::RestorableFolders`].
|
||||
ListRestorableFolders,
|
||||
/// Attach the given remote device folders to local paths and sync them down.
|
||||
/// Replies with [`Response::Ok`].
|
||||
RestoreSyncFolders { items: Vec<RestoreItem> },
|
||||
RestoreSyncFolders {
|
||||
items: Vec<RestoreItem>,
|
||||
},
|
||||
/// [`Request::ListRestorableFolders`] for another registered device, by
|
||||
/// uid, so its folders can be synced down to this machine. Replies with
|
||||
/// [`Response::RestorableFolders`].
|
||||
ListDeviceRestorableFolders { device: String },
|
||||
ListDeviceRestorableFolders {
|
||||
device: String,
|
||||
},
|
||||
/// [`Request::RestoreSyncFolders`] for folders under another device. A
|
||||
/// separate variant rather than an optional field: an older daemon that
|
||||
/// ignored the field would attach the folders under this machine's device
|
||||
@@ -571,9 +706,13 @@ pub enum Request {
|
||||
},
|
||||
/// List the members, pending invitations and public link of the node at
|
||||
/// mountpoint-relative `path`. Replies with [`Response::Share`].
|
||||
ListShare { path: String },
|
||||
ListShare {
|
||||
path: String,
|
||||
},
|
||||
/// The by-uid twin of [`Request::ListShare`].
|
||||
ListShareByUid { uid: String },
|
||||
ListShareByUid {
|
||||
uid: String,
|
||||
},
|
||||
/// Change the role of a share entry (member or pending invitation) on the node
|
||||
/// at `path`. `id` and `kind` identify the entry (from [`Response::Share`]).
|
||||
/// Replies with [`Response::Ok`].
|
||||
@@ -621,9 +760,15 @@ pub enum Request {
|
||||
},
|
||||
/// Remove the public link `id` from the node at `path`. Replies with
|
||||
/// [`Response::Ok`].
|
||||
RemovePublicLink { path: String, id: String },
|
||||
RemovePublicLink {
|
||||
path: String,
|
||||
id: String,
|
||||
},
|
||||
/// The by-uid twin of [`Request::RemovePublicLink`].
|
||||
RemovePublicLinkByUid { uid: String, id: String },
|
||||
RemovePublicLinkByUid {
|
||||
uid: String,
|
||||
id: String,
|
||||
},
|
||||
/// Change the public link `id` on the node at `path`, keeping its URL.
|
||||
/// `role` is "viewer" or "editor", or `None` to keep the current one.
|
||||
/// Replies with [`Response::PublicLink`].
|
||||
@@ -646,28 +791,48 @@ pub enum Request {
|
||||
/// invitation and every member. Each removal is attempted even if an
|
||||
/// earlier one fails. Replies with [`Response::Ok`], or an error naming
|
||||
/// what is still shared.
|
||||
StopSharing { path: String },
|
||||
StopSharing {
|
||||
path: String,
|
||||
},
|
||||
/// The by-uid twin of [`Request::StopSharing`].
|
||||
StopSharingByUid { uid: String },
|
||||
StopSharingByUid {
|
||||
uid: String,
|
||||
},
|
||||
|
||||
// ---- revisions --------------------------------------------------------
|
||||
/// List the version history of the file at mountpoint-relative `path`,
|
||||
/// newest first. Replies with [`Response::Revisions`].
|
||||
ListRevisions { path: String },
|
||||
ListRevisions {
|
||||
path: String,
|
||||
},
|
||||
/// The by-uid twin of [`Request::ListRevisions`].
|
||||
ListRevisionsByUid { uid: String },
|
||||
ListRevisionsByUid {
|
||||
uid: String,
|
||||
},
|
||||
/// Make revision `revision_id` of the file at `path` current again. The
|
||||
/// server applies this asynchronously, so the restored content may take a
|
||||
/// moment to appear. Replies with [`Response::Ok`].
|
||||
RestoreRevision { path: String, revision_id: String },
|
||||
RestoreRevision {
|
||||
path: String,
|
||||
revision_id: String,
|
||||
},
|
||||
/// The by-uid twin of [`Request::RestoreRevision`].
|
||||
RestoreRevisionByUid { uid: String, revision_id: String },
|
||||
RestoreRevisionByUid {
|
||||
uid: String,
|
||||
revision_id: String,
|
||||
},
|
||||
/// Permanently delete revision `revision_id` of the file at `path`. The
|
||||
/// content is unrecoverable, and the server refuses to delete the revision
|
||||
/// that is currently active. Replies with [`Response::Ok`].
|
||||
DeleteRevision { path: String, revision_id: String },
|
||||
DeleteRevision {
|
||||
path: String,
|
||||
revision_id: String,
|
||||
},
|
||||
/// The by-uid twin of [`Request::DeleteRevision`].
|
||||
DeleteRevisionByUid { uid: String, revision_id: String },
|
||||
DeleteRevisionByUid {
|
||||
uid: String,
|
||||
revision_id: String,
|
||||
},
|
||||
/// Write revision `revision_id` of the file at `path` to the absolute local
|
||||
/// path `dest`, leaving the file's current content untouched. Replies with
|
||||
/// [`Response::Ok`].
|
||||
@@ -699,15 +864,21 @@ pub enum Request {
|
||||
/// with [`Response::Entries`]; like [`Request::ListSharedWithMe`] the entries
|
||||
/// carry a `uid` and an empty `path`, since the subtree lives outside the
|
||||
/// mount. Lets a front-end browse into a shared folder.
|
||||
ListSharedFolder { uid: String },
|
||||
ListSharedFolder {
|
||||
uid: String,
|
||||
},
|
||||
/// Download a file shared with me into the content cache, addressed by `uid`.
|
||||
/// Replies with [`Response::FilePath`] so the front-end can open it with the
|
||||
/// default app. The by-uid twin of [`Request::OpenFile`], which can only
|
||||
/// address nodes inside the mount.
|
||||
OpenSharedFile { uid: String },
|
||||
OpenSharedFile {
|
||||
uid: String,
|
||||
},
|
||||
/// Leave a shared node by its `uid`, giving up my access. Replies with
|
||||
/// [`Response::Ok`].
|
||||
LeaveShared { uid: String },
|
||||
LeaveShared {
|
||||
uid: String,
|
||||
},
|
||||
|
||||
// ---- incoming invitations ---------------------------------------------
|
||||
/// List invitations addressed to me, pending accept or reject. Replies with
|
||||
@@ -715,9 +886,13 @@ pub enum Request {
|
||||
ListInvitations,
|
||||
/// Accept the invitation `id`, gaining access to the shared node. Replies with
|
||||
/// [`Response::Ok`].
|
||||
AcceptInvitation { id: String },
|
||||
AcceptInvitation {
|
||||
id: String,
|
||||
},
|
||||
/// Reject the invitation `id`, declining access. Replies with [`Response::Ok`].
|
||||
RejectInvitation { id: String },
|
||||
RejectInvitation {
|
||||
id: String,
|
||||
},
|
||||
|
||||
// ---- bookmarks --------------------------------------------------------
|
||||
/// List public links saved to my account. Replies with [`Response::Bookmarks`].
|
||||
@@ -729,7 +904,9 @@ pub enum Request {
|
||||
password: Option<String>,
|
||||
},
|
||||
/// Remove a saved bookmark by its `token`. Replies with [`Response::Ok`].
|
||||
DeleteBookmark { token: String },
|
||||
DeleteBookmark {
|
||||
token: String,
|
||||
},
|
||||
|
||||
// ---- account ----------------------------------------------------------
|
||||
/// Total account storage usage (used/total, all Proton products, not just
|
||||
@@ -743,7 +920,9 @@ pub enum Request {
|
||||
/// daemon performs (uploads, downloads, deletes, renames, shares, sync
|
||||
/// passes, …), so a front-end can show a running "what happened" feed
|
||||
/// without re-deriving it from anywhere.
|
||||
ListActivity { limit: usize },
|
||||
ListActivity {
|
||||
limit: usize,
|
||||
},
|
||||
|
||||
// ---- push -------------------------------------------------------------
|
||||
/// Keep the connection open and stream [`Event`] lines instead of one
|
||||
@@ -761,6 +940,10 @@ pub enum Topic {
|
||||
Files,
|
||||
/// The photos timeline or albums.
|
||||
Photos,
|
||||
/// The visible set of gallery media changed.
|
||||
GalleryVisibility,
|
||||
/// A remote Gallery visibility update arrived or its state became unavailable.
|
||||
GalleryVisibilitySynced,
|
||||
Trash,
|
||||
/// Shares, links, invitations and saved links, in either direction.
|
||||
Shares,
|
||||
@@ -785,9 +968,11 @@ impl Topic {
|
||||
/// Every topic a front-end can act on. A new subscription is told all of
|
||||
/// them have changed, so it catches up on whatever happened while it was
|
||||
/// not connected.
|
||||
pub const ALL: [Topic; 10] = [
|
||||
pub const ALL: [Topic; 12] = [
|
||||
Topic::Files,
|
||||
Topic::Photos,
|
||||
Topic::GalleryVisibility,
|
||||
Topic::GalleryVisibilitySynced,
|
||||
Topic::Trash,
|
||||
Topic::Shares,
|
||||
Topic::Devices,
|
||||
@@ -964,6 +1149,8 @@ pub enum SyncIssue {
|
||||
/// The account may no longer change the file or its folder, for example
|
||||
/// because a share was revoked.
|
||||
Access,
|
||||
/// The item or a folder involved in a move can be restored from Trash.
|
||||
Trashed,
|
||||
/// The file or the folder it goes into is gone from Drive.
|
||||
Missing,
|
||||
/// The folder holds too many items, or is nested too deep.
|
||||
@@ -981,6 +1168,7 @@ impl SyncIssue {
|
||||
match self {
|
||||
SyncIssue::Quota => "quota",
|
||||
SyncIssue::Access => "access",
|
||||
SyncIssue::Trashed => "trashed",
|
||||
SyncIssue::Missing => "missing",
|
||||
SyncIssue::Limit => "limit",
|
||||
SyncIssue::Rejected => "rejected",
|
||||
@@ -993,6 +1181,7 @@ impl SyncIssue {
|
||||
match name {
|
||||
"quota" => SyncIssue::Quota,
|
||||
"access" => SyncIssue::Access,
|
||||
"trashed" => SyncIssue::Trashed,
|
||||
"missing" => SyncIssue::Missing,
|
||||
"limit" => SyncIssue::Limit,
|
||||
"rejected" => SyncIssue::Rejected,
|
||||
@@ -1551,27 +1740,6 @@ pub enum PhotoKind {
|
||||
Raw,
|
||||
}
|
||||
|
||||
/// File-name extensions that denote a video, matched case-insensitively.
|
||||
const VIDEO_EXTS: &[&str] = &[
|
||||
"mkv", "mp4", "mov", "avi", "webm", "m4v", "flv", "wmv", "mpg", "mpeg", "ts", "3gp", "m2ts",
|
||||
"mts", "ogv",
|
||||
];
|
||||
|
||||
/// File-name extensions that denote a camera raw. The server media type for
|
||||
/// these is frequently a generic `application/octet-stream`, so the extension is
|
||||
/// the authoritative signal.
|
||||
const RAW_EXTS: &[&str] = &[
|
||||
"cr2", "cr3", "nef", "nrw", "arw", "srf", "sr2", "dng", "raf", "orf", "rw2", "srw", "pef",
|
||||
"raw", "rwl", "iiq", "3fr", "dcr", "kdc", "mrw", "x3f",
|
||||
];
|
||||
|
||||
/// File-name extensions that denote a ready-to-view still photo. Listed so a
|
||||
/// known image name classifies as a photo outright, without deferring to a media
|
||||
/// type that might disagree.
|
||||
const PHOTO_EXTS: &[&str] = &[
|
||||
"jpg", "jpeg", "png", "gif", "webp", "heic", "heif", "avif", "bmp", "tif", "tiff",
|
||||
];
|
||||
|
||||
impl PhotoKind {
|
||||
/// Classify a photo from what the daemon knows about it. A recognised
|
||||
/// file-name extension is authoritative — it is reliable even before the
|
||||
@@ -1579,26 +1747,11 @@ impl PhotoKind {
|
||||
/// useless generic — so the media type is only consulted for names that carry
|
||||
/// no extension we know. Anything still unresolved is a still photo.
|
||||
pub fn classify(name: Option<&str>, media_type: Option<&str>) -> PhotoKind {
|
||||
if let Some(ext) = name
|
||||
.and_then(|n| n.rsplit_once('.'))
|
||||
.map(|(_, e)| e.to_ascii_lowercase())
|
||||
{
|
||||
if RAW_EXTS.contains(&ext.as_str()) {
|
||||
return PhotoKind::Raw;
|
||||
}
|
||||
if VIDEO_EXTS.contains(&ext.as_str()) {
|
||||
return PhotoKind::Video;
|
||||
}
|
||||
if PHOTO_EXTS.contains(&ext.as_str()) {
|
||||
return PhotoKind::Photo;
|
||||
}
|
||||
match proton_gallery_rs::grouping::MediaClass::classify(name, media_type) {
|
||||
proton_gallery_rs::grouping::MediaClass::Photo => PhotoKind::Photo,
|
||||
proton_gallery_rs::grouping::MediaClass::Video => PhotoKind::Video,
|
||||
proton_gallery_rs::grouping::MediaClass::Raw => PhotoKind::Raw,
|
||||
}
|
||||
if let Some(mt) = media_type
|
||||
&& mt.starts_with("video/")
|
||||
{
|
||||
return PhotoKind::Video;
|
||||
}
|
||||
PhotoKind::Photo
|
||||
}
|
||||
|
||||
/// The stable integer this kind is persisted as (see the `kind` column of the
|
||||
@@ -1827,6 +1980,62 @@ pub struct MappingProgress {
|
||||
pub total: usize,
|
||||
}
|
||||
|
||||
/// Actions on saved Drive folder galleries.
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub enum GalleryAction {
|
||||
AuthenticateHidden,
|
||||
Lock,
|
||||
List {
|
||||
album: Option<GalleryPlace>,
|
||||
offset: usize,
|
||||
limit: usize,
|
||||
},
|
||||
PrivateList {
|
||||
album: Option<GalleryPlace>,
|
||||
proton: bool,
|
||||
offset: usize,
|
||||
limit: usize,
|
||||
},
|
||||
Folders {
|
||||
parent: Option<String>,
|
||||
},
|
||||
Add {
|
||||
uid: String,
|
||||
},
|
||||
Remove {
|
||||
gallery: String,
|
||||
},
|
||||
Refresh,
|
||||
Cover {
|
||||
album: GalleryPlace,
|
||||
uid: String,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct GalleryPlace {
|
||||
pub gallery: String,
|
||||
pub album: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct GalleryFolder {
|
||||
pub uid: String,
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct GalleryAlbum {
|
||||
pub place: GalleryPlace,
|
||||
#[serde(default)]
|
||||
pub proton: bool,
|
||||
pub folder: GalleryFolder,
|
||||
pub cover: Option<String>,
|
||||
pub items: u64,
|
||||
pub folders: u64,
|
||||
pub hidden: bool,
|
||||
}
|
||||
|
||||
/// One photo in a [`Request::PhotosTimeline`] page.
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct PhotoItem {
|
||||
@@ -2218,7 +2427,9 @@ pub enum Response {
|
||||
version: String,
|
||||
},
|
||||
/// A human-readable success message.
|
||||
Ok { message: String },
|
||||
Ok {
|
||||
message: String,
|
||||
},
|
||||
/// Health report for the metadata database and content cache (reply to
|
||||
/// [`Request::CacheInspect`]).
|
||||
CacheReport {
|
||||
@@ -2248,10 +2459,14 @@ pub enum Response {
|
||||
integrity_running: bool,
|
||||
},
|
||||
/// The pin registry.
|
||||
Pins { pins: Vec<Pin> },
|
||||
Pins {
|
||||
pins: Vec<Pin>,
|
||||
},
|
||||
/// A directory listing (reply to [`Request::ListDir`]) or a trash listing
|
||||
/// (reply to [`Request::ListTrash`]).
|
||||
Entries { entries: Vec<DirEntry> },
|
||||
Entries {
|
||||
entries: Vec<DirEntry>,
|
||||
},
|
||||
/// A page of the photos timeline. `available` is false when the account
|
||||
/// has no photos volume.
|
||||
Photos {
|
||||
@@ -2264,6 +2479,22 @@ pub enum Response {
|
||||
#[serde(default)]
|
||||
counts: Option<(usize, usize, usize)>,
|
||||
},
|
||||
GalleryFolders {
|
||||
folders: Vec<GalleryFolder>,
|
||||
},
|
||||
GalleryPage {
|
||||
albums: Vec<GalleryAlbum>,
|
||||
items: Vec<PhotoItem>,
|
||||
total: usize,
|
||||
},
|
||||
GalleryVideo {
|
||||
url: String,
|
||||
token: String,
|
||||
size: u64,
|
||||
},
|
||||
GalleryThumbnail {
|
||||
data: Option<String>,
|
||||
},
|
||||
/// The account's photo albums (reply to [`Request::PhotoAlbums`]).
|
||||
/// `available` is false when the account has no photos volume, matching
|
||||
/// [`Response::Photos`].
|
||||
@@ -2272,7 +2503,9 @@ pub enum Response {
|
||||
items: Vec<AlbumInfo>,
|
||||
},
|
||||
/// What the daemon is doing right now (reply to [`Request::Diagnostics`]).
|
||||
Diagnostics { diagnostics: Diagnostics },
|
||||
Diagnostics {
|
||||
diagnostics: Diagnostics,
|
||||
},
|
||||
/// How the Takeout import is doing (reply to [`Request::ImportStatus`]).
|
||||
/// `running` is false once it has finished, when `summary` is the final
|
||||
/// report; `summary` is `None` when no import has run this session.
|
||||
@@ -2298,12 +2531,19 @@ pub enum Response {
|
||||
#[serde(default)]
|
||||
summary: Option<RedateSummary>,
|
||||
},
|
||||
PhotoPresence {
|
||||
present: bool,
|
||||
},
|
||||
/// The months the timeline spans (reply to [`Request::PhotoMonths`]),
|
||||
/// newest first.
|
||||
PhotoMonths { months: Vec<PhotoMonth> },
|
||||
PhotoMonths {
|
||||
months: Vec<PhotoMonth>,
|
||||
},
|
||||
/// The duplicate sets (reply to [`Request::PhotoDuplicates`]), newest
|
||||
/// first. Each set lists the copy worth keeping first.
|
||||
PhotoDuplicates { sets: Vec<Vec<PhotoItem>> },
|
||||
PhotoDuplicates {
|
||||
sets: Vec<Vec<PhotoItem>>,
|
||||
},
|
||||
/// The sets of alike shots (reply to [`Request::PhotoSimilar`]), newest
|
||||
/// first, each in capture order; and how far hashing has got, `None`
|
||||
/// once no pass is running. `uncompared` counts the shots left out
|
||||
@@ -2325,9 +2565,13 @@ pub enum Response {
|
||||
},
|
||||
/// The photos of one town, each with its location (reply to
|
||||
/// [`Request::PlaceLocations`]).
|
||||
PhotoLocations { items: Vec<PhotoLocation> },
|
||||
PhotoLocations {
|
||||
items: Vec<PhotoLocation>,
|
||||
},
|
||||
/// Thumbnails for a [`Request::PhotoThumbs`] batch.
|
||||
Thumbs { items: Vec<PhotoThumb> },
|
||||
Thumbs {
|
||||
items: Vec<PhotoThumb>,
|
||||
},
|
||||
/// Per-node outcome of a [`Request::TrashNodes`] batch. Reported per uid
|
||||
/// rather than as one verdict: the server answers each node separately, and
|
||||
/// a front-end that removed all of them on a partial success would show a
|
||||
@@ -2337,7 +2581,9 @@ pub enum Response {
|
||||
failed: Vec<TrashFailure>,
|
||||
},
|
||||
/// The album a [`Request::CreateAlbum`] made.
|
||||
AlbumCreated { uid: String },
|
||||
AlbumCreated {
|
||||
uid: String,
|
||||
},
|
||||
/// Outcome of a [`Request::AddToAlbum`] or [`Request::RemoveFromAlbum`],
|
||||
/// per photo like [`Response::Trashed`]: `changed` photos were added or
|
||||
/// removed, `failed` ones were not.
|
||||
@@ -2351,20 +2597,33 @@ pub enum Response {
|
||||
FileThumbsStale,
|
||||
/// Daemon-issued generation reserved by
|
||||
/// [`Request::ReserveFileThumbGeneration`].
|
||||
FileThumbGeneration { generation: u64 },
|
||||
FileThumbGeneration {
|
||||
generation: u64,
|
||||
},
|
||||
/// Current recursive thumbnail-build progress.
|
||||
ThumbnailBuild { status: ThumbnailBuildStatus },
|
||||
ThumbnailBuild {
|
||||
status: ThumbnailBuildStatus,
|
||||
},
|
||||
/// Whether a photos-timeline refresh is still running (reply to
|
||||
/// [`Request::PhotosRefreshStatus`]).
|
||||
PhotosRefresh { running: bool },
|
||||
PhotosRefresh {
|
||||
running: bool,
|
||||
},
|
||||
/// An on-disk path the front-end can open (e.g. a downloaded photo).
|
||||
FilePath { path: String },
|
||||
FilePath {
|
||||
path: String,
|
||||
},
|
||||
/// Full-text search results (reply to [`Request::Search`]).
|
||||
SearchResults { hits: Vec<SearchHit> },
|
||||
SearchResults {
|
||||
hits: Vec<SearchHit>,
|
||||
},
|
||||
/// Local-file search results (reply to [`Request::SearchLocal`]). `indexing`
|
||||
/// is true while a scan of the machine is still running, so a front-end can
|
||||
/// say "still indexing" instead of "no matches" on a cold first launch.
|
||||
LocalResults { hits: Vec<LocalHit>, indexing: bool },
|
||||
LocalResults {
|
||||
hits: Vec<LocalHit>,
|
||||
indexing: bool,
|
||||
},
|
||||
/// Drive and local-file search results returned together (reply to
|
||||
/// [`Request::SearchV2`]). `local_indexing` distinguishes a genuinely empty
|
||||
/// local result set from one observed while the initial scan is running.
|
||||
@@ -2383,17 +2642,29 @@ pub enum Response {
|
||||
jobs: Vec<JobItem>,
|
||||
},
|
||||
/// The account's devices (reply to [`Request::ListDevices`]).
|
||||
Devices { items: Vec<DeviceInfo> },
|
||||
Devices {
|
||||
items: Vec<DeviceInfo>,
|
||||
},
|
||||
/// Every local Proton Drive location (reply to [`Request::ListLocations`]).
|
||||
Locations { items: Vec<MountSpec> },
|
||||
Locations {
|
||||
items: Vec<MountSpec>,
|
||||
},
|
||||
/// This device's synced folders (reply to [`Request::ListSyncFolders`]).
|
||||
SyncFolders { items: Vec<SyncFolderInfo> },
|
||||
SyncFolders {
|
||||
items: Vec<SyncFolderInfo>,
|
||||
},
|
||||
/// The upload/change queue (reply to [`Request::ListPendingOps`]).
|
||||
PendingOps { items: Vec<PendingOpInfo> },
|
||||
PendingOps {
|
||||
items: Vec<PendingOpInfo>,
|
||||
},
|
||||
/// Conflict copies (reply to [`Request::ListConflicts`]).
|
||||
Conflicts { items: Vec<ConflictInfo> },
|
||||
Conflicts {
|
||||
items: Vec<ConflictInfo>,
|
||||
},
|
||||
/// Folders offered for restore (reply to [`Request::ListRestorableFolders`]).
|
||||
RestorableFolders { items: Vec<RestorableFolder> },
|
||||
RestorableFolders {
|
||||
items: Vec<RestorableFolder>,
|
||||
},
|
||||
/// A node's share: members + pending invitations, and its public link if any
|
||||
/// (reply to [`Request::ListShare`]).
|
||||
Share {
|
||||
@@ -2403,28 +2674,46 @@ pub enum Response {
|
||||
/// A freshly created or changed public link, carrying the shareable URL
|
||||
/// (reply to [`Request::CreatePublicLink`] and
|
||||
/// [`Request::UpdatePublicLink`]).
|
||||
PublicLink { link: PublicLinkInfo },
|
||||
PublicLink {
|
||||
link: PublicLinkInfo,
|
||||
},
|
||||
/// What a folder holds on Proton Drive (reply to [`Request::FolderSize`]):
|
||||
/// the bytes on storage and the number of items below it, folders and
|
||||
/// trashed items included.
|
||||
FolderSize { size: u64, items: u64 },
|
||||
FolderSize {
|
||||
size: u64,
|
||||
items: u64,
|
||||
},
|
||||
/// Invitations addressed to me (reply to [`Request::ListInvitations`]).
|
||||
Invitations { items: Vec<InvitationInfo> },
|
||||
Invitations {
|
||||
items: Vec<InvitationInfo>,
|
||||
},
|
||||
/// Saved public links (reply to [`Request::ListBookmarks`]).
|
||||
Bookmarks { items: Vec<BookmarkInfo> },
|
||||
Bookmarks {
|
||||
items: Vec<BookmarkInfo>,
|
||||
},
|
||||
/// Account storage usage in bytes (reply to [`Request::AccountQuota`]).
|
||||
/// `max_space` is the total; `used_space` what is consumed. `max_space == 0`
|
||||
/// means the total is unknown, which a front-end shows as a plain used figure
|
||||
/// rather than a full bar.
|
||||
AccountQuota { max_space: i64, used_space: i64 },
|
||||
AccountQuota {
|
||||
max_space: i64,
|
||||
used_space: i64,
|
||||
},
|
||||
/// Nodes I have shared with others (reply to [`Request::ListSharedByMe`]).
|
||||
SharedByMe { items: Vec<SharedItem> },
|
||||
SharedByMe {
|
||||
items: Vec<SharedItem>,
|
||||
},
|
||||
/// A file's version history, newest first (reply to
|
||||
/// [`Request::ListRevisions`]).
|
||||
Revisions { items: Vec<RevisionInfo> },
|
||||
Revisions {
|
||||
items: Vec<RevisionInfo>,
|
||||
},
|
||||
/// The daemon's recent activity, newest first (reply to
|
||||
/// [`Request::ListActivity`]).
|
||||
Activity { items: Vec<ActivityEntry> },
|
||||
Activity {
|
||||
items: Vec<ActivityEntry>,
|
||||
},
|
||||
/// The request failed. `message` is for the user; `kind` is for the code —
|
||||
/// a front-end decides its copy and whether to offer a retry from `kind`,
|
||||
/// never by matching on the text.
|
||||
@@ -2523,6 +2812,8 @@ impl Request {
|
||||
pub fn read_timeout(&self) -> Duration {
|
||||
if self.is_poll() {
|
||||
POLL_READ_TIMEOUT
|
||||
} else if matches!(self, Request::DriveGallery { .. }) {
|
||||
Duration::from_secs(300)
|
||||
} else {
|
||||
READ_TIMEOUT
|
||||
}
|
||||
@@ -2869,7 +3160,7 @@ mod tests {
|
||||
/// videos back to the expensive whole-file path.
|
||||
#[test]
|
||||
fn photo_kind_recognises_every_supported_video_extension() {
|
||||
for ext in VIDEO_EXTS {
|
||||
for ext in proton_gallery_rs::grouping::VIDEO_EXTENSIONS {
|
||||
let lower = format!("movie.{ext}");
|
||||
let upper = format!("MOVIE.{}", ext.to_ascii_uppercase());
|
||||
assert_eq!(
|
||||
|
||||
@@ -31,8 +31,30 @@ pub struct StoredAlbum {
|
||||
impl Db {
|
||||
/// Replace the album listing wholesale, in the given order.
|
||||
pub fn albums_replace(&self, albums: &[StoredAlbum]) -> Result<()> {
|
||||
self.albums_replace_impl(albums, None).map(|_| ())
|
||||
}
|
||||
|
||||
pub fn albums_replace_at(
|
||||
&self,
|
||||
albums: &[StoredAlbum],
|
||||
generation: i64,
|
||||
now: i64,
|
||||
) -> Result<bool> {
|
||||
self.albums_replace_impl(albums, Some((generation, now)))
|
||||
}
|
||||
|
||||
fn albums_replace_impl(
|
||||
&self,
|
||||
albums: &[StoredAlbum],
|
||||
stamp: Option<(i64, i64)>,
|
||||
) -> Result<bool> {
|
||||
let mut conn = self.conn.lock();
|
||||
let tx = conn.transaction()?;
|
||||
if let Some((generation, _)) = stamp
|
||||
&& super::photos::photos_generation(&tx)? != generation
|
||||
{
|
||||
return Ok(false);
|
||||
}
|
||||
// Contents of an album that no longer exists (unshared, deleted) go with
|
||||
// it — otherwise they would linger forever, keyed by an album uid no
|
||||
// listing mentions again.
|
||||
@@ -56,7 +78,11 @@ impl Db {
|
||||
let mut stmt = tx.prepare(
|
||||
"INSERT INTO albums
|
||||
(uid, name, photo_count, cover_uid, last_activity, shared, seq)
|
||||
VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7)",
|
||||
SELECT ?1,?2,?3,
|
||||
CASE WHEN EXISTS(SELECT 1 FROM photo_tombstones WHERE uid=?4)
|
||||
THEN (SELECT uid FROM album_photos WHERE album_uid=?1 ORDER BY seq LIMIT 1) ELSE ?4 END,
|
||||
?5,?6,?7
|
||||
WHERE NOT EXISTS(SELECT 1 FROM photo_tombstones WHERE uid=?1)",
|
||||
)?;
|
||||
for (seq, album) in albums.iter().enumerate() {
|
||||
stmt.execute(params![
|
||||
@@ -70,8 +96,11 @@ impl Db {
|
||||
])?;
|
||||
}
|
||||
}
|
||||
if let Some((_, now)) = stamp {
|
||||
super::photos::gallery_state(&tx, "albums_synced_ms", now)?;
|
||||
}
|
||||
tx.commit()?;
|
||||
Ok(())
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
/// The persisted album listing, in stored order.
|
||||
@@ -111,15 +140,44 @@ impl Db {
|
||||
album_uid: &str,
|
||||
items: &[(String, i64, Option<String>, Option<String>)],
|
||||
) -> Result<()> {
|
||||
self.album_photos_replace_impl(album_uid, items, None)
|
||||
.map(|_| ())
|
||||
}
|
||||
|
||||
pub fn album_photos_replace_at(
|
||||
&self,
|
||||
album_uid: &str,
|
||||
items: &[(String, i64, Option<String>, Option<String>)],
|
||||
generation: i64,
|
||||
now: i64,
|
||||
) -> Result<bool> {
|
||||
self.album_photos_replace_impl(album_uid, items, Some((generation, now)))
|
||||
}
|
||||
|
||||
fn album_photos_replace_impl(
|
||||
&self,
|
||||
album_uid: &str,
|
||||
items: &[(String, i64, Option<String>, Option<String>)],
|
||||
stamp: Option<(i64, i64)>,
|
||||
) -> Result<bool> {
|
||||
let mut conn = self.conn.lock();
|
||||
let tx = conn.transaction()?;
|
||||
let learned: HashMap<String, (Option<f64>, i64, Option<String>)> = {
|
||||
if let Some((generation, _)) = stamp
|
||||
&& super::photos::photos_generation(&tx)? != generation
|
||||
{
|
||||
return Ok(false);
|
||||
}
|
||||
type StoredPhotoMetadata = (Option<f64>, i64, Option<String>, Option<String>);
|
||||
let learned: HashMap<String, StoredPhotoMetadata> = {
|
||||
let mut stmt = tx.prepare(
|
||||
"SELECT uid, ratio, thumb_state, media_type FROM album_photos
|
||||
"SELECT uid, ratio, thumb_state, media_type, name FROM album_photos
|
||||
WHERE album_uid = ?1",
|
||||
)?;
|
||||
let rows = stmt.query_map([album_uid], |r| {
|
||||
Ok((r.get::<_, String>(0)?, (r.get(1)?, r.get(2)?, r.get(3)?)))
|
||||
Ok((
|
||||
r.get::<_, String>(0)?,
|
||||
(r.get(1)?, r.get(2)?, r.get(3)?, r.get(4)?),
|
||||
))
|
||||
})?;
|
||||
rows.collect::<rusqlite::Result<_>>()?
|
||||
};
|
||||
@@ -128,15 +186,17 @@ impl Db {
|
||||
{
|
||||
let mut stmt = tx.prepare(
|
||||
"INSERT INTO album_photos
|
||||
(album_uid, uid, capture_time, name, media_type, kind, ratio, thumb_state, seq)
|
||||
VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9)",
|
||||
(album_uid, uid, capture_time, name, media_type, kind, ratio, thumb_state, seq, resolved)
|
||||
SELECT ?1,?2,?3,?4,?5,?6,?7,?8,?9,?10
|
||||
WHERE NOT EXISTS(SELECT 1 FROM photo_tombstones WHERE uid IN (?1,?2))",
|
||||
)?;
|
||||
for (seq, (uid, capture_time, name, media_type)) in items.iter().enumerate() {
|
||||
let (ratio, thumb_state, learned_media) =
|
||||
learned
|
||||
.get(uid)
|
||||
.cloned()
|
||||
.unwrap_or((None, THUMB_UNKNOWN, None));
|
||||
let (ratio, thumb_state, learned_media, learned_name) = learned
|
||||
.get(uid)
|
||||
.cloned()
|
||||
.unwrap_or((None, THUMB_UNKNOWN, None, None));
|
||||
let resolved = name.is_some();
|
||||
let name = name.clone().or(learned_name);
|
||||
let media_type = media_type.clone().or(learned_media);
|
||||
let kind =
|
||||
crate::control::PhotoKind::classify(name.as_deref(), media_type.as_deref());
|
||||
@@ -150,11 +210,32 @@ impl Db {
|
||||
ratio,
|
||||
thumb_state,
|
||||
seq as i64,
|
||||
resolved,
|
||||
])?;
|
||||
}
|
||||
}
|
||||
if let Some((_, now)) = stamp {
|
||||
super::photos::gallery_state(&tx, &format!("album_synced_ms:{album_uid}"), now)?;
|
||||
}
|
||||
tx.commit()?;
|
||||
Ok(())
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
/// Reuse current timeline metadata and resolved album-only metadata.
|
||||
pub fn album_photo_metadata(
|
||||
&self,
|
||||
album: &str,
|
||||
) -> Result<HashMap<String, (String, Option<String>)>> {
|
||||
let conn = self.read();
|
||||
let mut stmt = conn.prepare(
|
||||
"SELECT uid,name,media_type FROM album_photos
|
||||
WHERE album_uid=?1 AND resolved=1 AND name IS NOT NULL
|
||||
UNION ALL SELECT uid,name,media_type FROM photos
|
||||
WHERE resolved_at IS NOT NULL AND name IS NOT NULL",
|
||||
)?;
|
||||
Ok(stmt
|
||||
.query_map([album], |r| Ok((r.get(0)?, (r.get(1)?, r.get(2)?))))?
|
||||
.collect::<rusqlite::Result<_>>()?)
|
||||
}
|
||||
|
||||
/// One page of an album's photos, in stored order.
|
||||
@@ -163,33 +244,47 @@ impl Db {
|
||||
album_uid: &str,
|
||||
offset: usize,
|
||||
limit: usize,
|
||||
) -> Result<Vec<StoredPhoto>> {
|
||||
self.album_photos_page_visible(album_uid, offset, limit, "[]")
|
||||
}
|
||||
|
||||
pub fn album_photos_page_visible(
|
||||
&self,
|
||||
album_uid: &str,
|
||||
offset: usize,
|
||||
limit: usize,
|
||||
excluded: &str,
|
||||
) -> Result<Vec<StoredPhoto>> {
|
||||
let conn = self.read();
|
||||
let mut stmt = conn.prepare(
|
||||
"SELECT uid, capture_time, name, ratio, thumb_state, kind FROM album_photos
|
||||
WHERE album_uid = ?1 ORDER BY seq LIMIT ?2 OFFSET ?3",
|
||||
WHERE album_uid = ?1 AND uid NOT IN (SELECT value FROM json_each(?4))
|
||||
ORDER BY seq LIMIT ?2 OFFSET ?3",
|
||||
)?;
|
||||
let rows = stmt
|
||||
.query_map(params![album_uid, limit as i64, offset as i64], |r| {
|
||||
Ok(StoredPhoto {
|
||||
uid: r.get(0)?,
|
||||
capture_time: r.get(1)?,
|
||||
name: r.get(2)?,
|
||||
ratio: r.get(3)?,
|
||||
thumb_state: r.get(4)?,
|
||||
kind: crate::control::PhotoKind::from_i64(r.get(5)?),
|
||||
// Album rows have no favorite state of their own: an album
|
||||
// photo on someone else's volume is not in our timeline, and
|
||||
// favouriting one is not supported yet anyway.
|
||||
favorite: false,
|
||||
// Nor are album rows grouped: an album is a list the user
|
||||
// made, and it shows exactly what they put in it.
|
||||
group_size: 1,
|
||||
has_raw: false,
|
||||
// Album rows carry no location.
|
||||
place_id: None,
|
||||
})
|
||||
})?
|
||||
.query_map(
|
||||
params![album_uid, limit as i64, offset as i64, excluded],
|
||||
|r| {
|
||||
Ok(StoredPhoto {
|
||||
uid: r.get(0)?,
|
||||
capture_time: r.get(1)?,
|
||||
name: r.get(2)?,
|
||||
ratio: r.get(3)?,
|
||||
thumb_state: r.get(4)?,
|
||||
kind: crate::control::PhotoKind::from_i64(r.get(5)?),
|
||||
// Album rows have no favorite state of their own: an album
|
||||
// photo on someone else's volume is not in our timeline, and
|
||||
// favouriting one is not supported yet anyway.
|
||||
favorite: false,
|
||||
// Nor are album rows grouped: an album is a list the user
|
||||
// made, and it shows exactly what they put in it.
|
||||
group_size: 1,
|
||||
has_raw: false,
|
||||
// Album rows carry no location.
|
||||
place_id: None,
|
||||
})
|
||||
},
|
||||
)?
|
||||
.collect::<rusqlite::Result<_>>()?;
|
||||
Ok(rows)
|
||||
}
|
||||
|
||||
@@ -108,7 +108,8 @@ impl Db {
|
||||
Ok(total.max(0) as u64)
|
||||
}
|
||||
|
||||
/// The `limit` least-recently-accessed entries of `kind`, oldest first.
|
||||
/// The `limit` least-recently-accessed entries of `kind` after `offset`,
|
||||
/// oldest first.
|
||||
///
|
||||
/// Eviction wants a handful of victims, not the whole table. Bounded so a
|
||||
/// pass over a large cache does not read every row to drop a few, and so the
|
||||
@@ -118,13 +119,14 @@ impl Db {
|
||||
&self,
|
||||
kind: &str,
|
||||
limit: usize,
|
||||
offset: usize,
|
||||
) -> Result<Vec<(String, u64)>> {
|
||||
let conn = self.read();
|
||||
let mut stmt = conn.prepare_cached(
|
||||
"SELECT cache_key, size_bytes FROM cache_entries
|
||||
WHERE kind = ?1 ORDER BY last_accessed ASC LIMIT ?2",
|
||||
WHERE kind = ?1 ORDER BY last_accessed ASC LIMIT ?2 OFFSET ?3",
|
||||
)?;
|
||||
let rows = stmt.query_map(params![kind, limit as i64], |r| {
|
||||
let rows = stmt.query_map(params![kind, limit as i64, offset as i64], |r| {
|
||||
Ok((r.get::<_, String>(0)?, r.get::<_, i64>(1)?.max(0) as u64))
|
||||
})?;
|
||||
let mut out = Vec::new();
|
||||
|
||||
@@ -11,7 +11,7 @@ use super::Db;
|
||||
use crate::Result;
|
||||
|
||||
/// Current schema version. Bump on every forward migration added below.
|
||||
pub(super) const SCHEMA_VERSION: i64 = 45;
|
||||
pub(super) const SCHEMA_VERSION: i64 = 46;
|
||||
|
||||
impl Db {
|
||||
pub(super) fn migrate(&self) -> Result<()> {
|
||||
@@ -490,6 +490,17 @@ impl Db {
|
||||
}
|
||||
}
|
||||
}
|
||||
if current < 46 {
|
||||
tx.execute_batch(MIGRATION_V46)?;
|
||||
let has_resolved: bool = tx.query_row(
|
||||
"SELECT EXISTS(SELECT 1 FROM pragma_table_info('album_photos') WHERE name='resolved')",
|
||||
[],
|
||||
|row| row.get(0),
|
||||
)?;
|
||||
if !has_resolved {
|
||||
tx.execute_batch(MIGRATION_V46_ALBUM_PHOTOS)?;
|
||||
}
|
||||
}
|
||||
tx.execute(
|
||||
"INSERT INTO sync_state (key, value) VALUES ('schema_version', ?1)
|
||||
ON CONFLICT(key) DO UPDATE SET value = excluded.value",
|
||||
@@ -1459,3 +1470,13 @@ BEGIN
|
||||
UPDATE mount SET kind = NEW.kind WHERE sync_folder_id = NEW.id;
|
||||
END;
|
||||
";
|
||||
|
||||
/// Keep deletion evidence across listing races and remember unresolved album metadata.
|
||||
const MIGRATION_V46: &str = "
|
||||
CREATE TABLE IF NOT EXISTS photo_tombstones(uid TEXT PRIMARY KEY);
|
||||
";
|
||||
|
||||
const MIGRATION_V46_ALBUM_PHOTOS: &str = "
|
||||
ALTER TABLE album_photos ADD COLUMN resolved INTEGER NOT NULL DEFAULT 0;
|
||||
UPDATE album_photos SET resolved=1 WHERE name IS NOT NULL;
|
||||
";
|
||||
@@ -445,6 +445,13 @@ fn is_in_memory(path: &Path) -> bool {
|
||||
/// SQLite uses POSIX record locks, so the two never interact, and a lock file
|
||||
/// left behind carries no state — the lock lives in the kernel and dies with
|
||||
/// the process, however it exits.
|
||||
///
|
||||
/// A refusal is retried for [`LOCK_RETRY`] before it counts as another
|
||||
/// daemon. A child this process spawns holds a copy of every descriptor from
|
||||
/// its fork until its exec closes them, and `flock` belongs to the open file,
|
||||
/// not the descriptor. So a lock the process has just let go of can stay held
|
||||
/// for that moment, and a reopen right after a drop is refused
|
||||
/// (`docs/BUGS.md` B290).
|
||||
fn acquire_single_writer_lock(path: &Path) -> Result<Option<File>> {
|
||||
if is_in_memory(path) {
|
||||
return Ok(None);
|
||||
@@ -456,22 +463,32 @@ fn acquire_single_writer_lock(path: &Path) -> Result<Option<File>> {
|
||||
.truncate(false)
|
||||
.write(true)
|
||||
.open(&lock_path)?;
|
||||
// SAFETY: `file` owns the descriptor and outlives the call.
|
||||
let rc = unsafe { libc::flock(file.as_raw_fd(), libc::LOCK_EX | libc::LOCK_NB) };
|
||||
if rc != 0 {
|
||||
let deadline = std::time::Instant::now() + LOCK_RETRY;
|
||||
loop {
|
||||
// SAFETY: `file` owns the descriptor and outlives the call.
|
||||
let rc = unsafe { libc::flock(file.as_raw_fd(), libc::LOCK_EX | libc::LOCK_NB) };
|
||||
if rc == 0 {
|
||||
return Ok(Some(file));
|
||||
}
|
||||
let e = std::io::Error::last_os_error();
|
||||
if e.raw_os_error() == Some(libc::EWOULDBLOCK) {
|
||||
if e.raw_os_error() != Some(libc::EWOULDBLOCK) {
|
||||
return Err(Error::Io(e));
|
||||
}
|
||||
if std::time::Instant::now() >= deadline {
|
||||
return Err(Error::Other(format!(
|
||||
"another Proton Drive daemon is already using {} — \
|
||||
stop it first (`systemctl --user stop proton-drive.service`)",
|
||||
path.display()
|
||||
)));
|
||||
}
|
||||
return Err(Error::Io(e));
|
||||
std::thread::sleep(std::time::Duration::from_millis(20));
|
||||
}
|
||||
Ok(Some(file))
|
||||
}
|
||||
|
||||
/// How long a refused single-writer lock is retried; far longer than a fork
|
||||
/// takes to reach its exec, far shorter than anyone notices.
|
||||
const LOCK_RETRY: std::time::Duration = std::time::Duration::from_millis(500);
|
||||
|
||||
fn lock_path_for(path: &Path) -> PathBuf {
|
||||
let mut name = path.as_os_str().to_owned();
|
||||
name.push(".lock");
|
||||
|
||||
@@ -252,9 +252,32 @@ const UID_NOW: &str = "COALESCE((SELECT uid FROM nodes WHERE lid = pending_op.li
|
||||
const PARENT_NOW: &str =
|
||||
"COALESCE((SELECT uid FROM nodes WHERE lid = pending_op.parent_lid), parent_uid)";
|
||||
|
||||
/// Whether any queued move takes a node out of the folder `source.uid`.
|
||||
/// A move updates the local node tree immediately, so its original parent
|
||||
/// comes from the queue, including while a worker is sending it to Drive.
|
||||
const MOVES_OUT_OF_FOLDER: &str = "
|
||||
COALESCE((SELECT is_dir FROM nodes WHERE uid = source.uid), 1) = 1
|
||||
AND EXISTS (
|
||||
WITH RECURSIVE folders(uid, lid) AS (
|
||||
SELECT source.uid, (SELECT lid FROM nodes WHERE uid = source.uid)
|
||||
UNION
|
||||
SELECT n.uid, n.lid FROM nodes n JOIN folders f
|
||||
ON n.parent_lid = f.lid OR (n.parent_lid IS NULL AND n.parent_uid = f.uid)
|
||||
WHERE n.is_dir = 1
|
||||
)
|
||||
SELECT 1 FROM pending_op AS move
|
||||
WHERE move.kind = 'rename'
|
||||
AND CASE WHEN json_valid(move.meta_json)
|
||||
THEN json_extract(move.meta_json, '$.original_parent_uid') END
|
||||
IN (SELECT uid FROM folders)
|
||||
AND move.parent_uid IS NOT NULL
|
||||
AND NOT EXISTS (SELECT 1 FROM folders f
|
||||
WHERE f.lid = move.parent_lid OR f.uid = move.parent_uid)
|
||||
)";
|
||||
|
||||
/// The `WHERE` terms for a row a drain worker may claim once it falls due: not
|
||||
/// claimed already, no other claimed op on the same node, and not under a
|
||||
/// folder that has yet to land.
|
||||
/// claimed already, no other claimed op on the same node, no pending creation
|
||||
/// of its parent, and no moves that still need a folder we are about to trash.
|
||||
///
|
||||
/// One fragment for [`Db::claim_next_due_op`] and [`Db::earliest_due_at`]. A
|
||||
/// row the claim skips but the wait counts is due "now" for as long as it is
|
||||
@@ -265,7 +288,9 @@ fn claimable() -> String {
|
||||
AND (parent_uid IS NULL OR substr({PARENT_NOW}, 1, {n}) <> '{v}~')
|
||||
AND uid NOT IN (SELECT uid FROM pending_op WHERE claimed_at <> 0)
|
||||
AND (lid IS NULL OR lid NOT IN (
|
||||
SELECT lid FROM pending_op WHERE claimed_at <> 0 AND lid IS NOT NULL))",
|
||||
SELECT lid FROM pending_op WHERE claimed_at <> 0 AND lid IS NOT NULL))
|
||||
AND (kind <> 'trash' OR NOT EXISTS (
|
||||
SELECT 1 FROM (SELECT {UID_NOW} AS uid) AS source WHERE {MOVES_OUT_OF_FOLDER}))",
|
||||
v = LOCAL_VOLUME,
|
||||
n = LOCAL_VOLUME.len() + 1,
|
||||
)
|
||||
@@ -475,19 +500,40 @@ pub struct AttachedBlob {
|
||||
}
|
||||
|
||||
impl Db {
|
||||
/// Whether a queued trash still holds `name` somewhere.
|
||||
/// A folder can look empty locally while Drive still holds the queued
|
||||
/// moves' source files. A trash has to go through the drain in that case.
|
||||
pub fn has_pending_moves_out_of(&self, uid: &str) -> Result<bool> {
|
||||
let conn = self.read();
|
||||
Ok(conn
|
||||
.prepare_cached(&format!(
|
||||
"SELECT EXISTS (SELECT 1 FROM (SELECT ?1 AS uid) AS source
|
||||
WHERE {MOVES_OUT_OF_FOLDER})"
|
||||
))?
|
||||
.query_row(params![uid], |row| row.get(0))?)
|
||||
}
|
||||
|
||||
/// Whether a queued trash still holds `name` in `parent_uid`.
|
||||
///
|
||||
/// A replacing rename or a delete-then-recreate queues the trash of the old
|
||||
/// node ahead of the op that wants its name. With several drain workers the
|
||||
/// later op can run first and find the name still taken; this tells it to
|
||||
/// wait for the trash rather than land under a conflict name.
|
||||
pub fn has_pending_trash_named(&self, name: &str) -> Result<bool> {
|
||||
/// wait for the trash rather than land under a conflict name. Older rows
|
||||
/// whose node and parent are unknown are matched by name alone.
|
||||
pub fn has_pending_trash_named(&self, name: &str, parent_uid: Option<&str>) -> Result<bool> {
|
||||
let conn = self.read();
|
||||
conn.query_row(
|
||||
"SELECT EXISTS(
|
||||
SELECT 1 FROM pending_op WHERE kind = ?1 AND name = ?2
|
||||
)",
|
||||
params![OP_TRASH, name],
|
||||
SELECT 1 FROM pending_op AS p
|
||||
WHERE p.kind = ?1 AND p.name = ?2
|
||||
AND (?3 IS NULL OR ?3 = COALESCE(
|
||||
(SELECT uid FROM nodes WHERE lid = p.parent_lid),
|
||||
p.parent_uid,
|
||||
(SELECT COALESCE(parent.uid, n.parent_uid)
|
||||
FROM nodes n LEFT JOIN nodes parent ON parent.lid = n.parent_lid
|
||||
WHERE n.uid = p.uid),
|
||||
?3))
|
||||
)",
|
||||
params![OP_TRASH, name, parent_uid],
|
||||
|row| row.get(0),
|
||||
)
|
||||
.map_err(Into::into)
|
||||
@@ -1219,7 +1265,7 @@ impl Db {
|
||||
/// the claim is a column: a row is offered to exactly one worker, and the
|
||||
/// worker that took it is the only one that may retire, defer or fail it.
|
||||
///
|
||||
/// Two exclusions on top of [`next_due_op`](Self::next_due_op)'s:
|
||||
/// The selected row must also satisfy [`claimable`]:
|
||||
///
|
||||
/// * `claimed_at = 0` — not already in flight somewhere else.
|
||||
/// * no *other* claimed op shares this `uid`. Ordering only has to hold per
|
||||
@@ -1229,6 +1275,8 @@ impl Db {
|
||||
/// pending entry. `ORDER BY id` plus this exclusion gives per-uid serial
|
||||
/// order for free — the older op is claimed first and the newer one is
|
||||
/// invisible until it retires.
|
||||
/// * its destination folder already exists remotely.
|
||||
/// * a folder trash waits for pending moves out of that folder's subtree.
|
||||
///
|
||||
/// Select and mark are one transaction, so two workers cannot both see the
|
||||
/// row as unclaimed.
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
//! The photos timeline: a flat, date-ordered projection of the photo share,
|
||||
//! persisted so the gallery opens instantly instead of re-enumerating on launch.
|
||||
|
||||
use rusqlite::params;
|
||||
use rusqlite::{Connection, OptionalExtension, Transaction, params};
|
||||
|
||||
use std::collections::{HashMap, HashSet};
|
||||
|
||||
use proton_gallery_rs::grouping::{Grouped, group_photos, name_stem};
|
||||
|
||||
use super::Db;
|
||||
use crate::Result;
|
||||
|
||||
@@ -121,135 +123,6 @@ fn capture_day(conn: &rusqlite::Connection, capture_time: i64) -> Option<String>
|
||||
.flatten()
|
||||
}
|
||||
|
||||
/// The file name without its extension, lowercased — `IMG_1234.CR2` and
|
||||
/// `IMG_1234.JPG` share `img_1234` — with the camera's own part-of-a-shot
|
||||
/// marker removed, so the two files a raw capture writes share a stem too.
|
||||
fn name_stem(name: Option<&str>) -> Option<String> {
|
||||
let name = name?;
|
||||
let stem = match name.rsplit_once('.') {
|
||||
Some((stem, _)) if !stem.is_empty() => stem,
|
||||
_ => name,
|
||||
};
|
||||
let stem = stem.to_ascii_lowercase();
|
||||
Some(strip_shot_marker(&stem).to_string())
|
||||
}
|
||||
|
||||
/// Drop a `.RAW-NN.ROLE` marker from a stem.
|
||||
///
|
||||
/// Pixel stores one raw capture as `PXL_20260919_000625670.RAW-01.COVER.jpg`
|
||||
/// and `PXL_20260919_000625670.RAW-02.ORIGINAL.dng`: one shot, two files, two
|
||||
/// stems that differ in exactly the part naming which file of the shot this is.
|
||||
/// Cutting the marker off is what lets rule 2 see the pair. The check is narrow
|
||||
/// on purpose — digits, then a single role word — so an ordinary name that
|
||||
/// happens to contain `.raw-` keeps its stem.
|
||||
fn strip_shot_marker(stem: &str) -> &str {
|
||||
let Some(at) = stem.rfind(".raw-") else {
|
||||
return stem;
|
||||
};
|
||||
let rest = &stem[at + ".raw-".len()..];
|
||||
let Some((index, role)) = rest.split_once('.') else {
|
||||
return stem;
|
||||
};
|
||||
let marked = !index.is_empty()
|
||||
&& index.bytes().all(|b| b.is_ascii_digit())
|
||||
&& !role.is_empty()
|
||||
&& role.bytes().all(|b| b.is_ascii_alphabetic());
|
||||
if marked { &stem[..at] } else { stem }
|
||||
}
|
||||
|
||||
/// One entry of the grouping pass: what rule 2 needs, plus what choosing a
|
||||
/// representative needs.
|
||||
struct Grouped {
|
||||
uid: String,
|
||||
kind: crate::control::PhotoKind,
|
||||
main_uid: Option<String>,
|
||||
day: Option<String>,
|
||||
stem: Option<String>,
|
||||
}
|
||||
|
||||
/// Which group each photo belongs to, and which member of it the gallery shows.
|
||||
///
|
||||
/// Precedence, as agreed:
|
||||
///
|
||||
/// 1. The server's own relation — a photo with a `main_photo_uid` joins that
|
||||
/// photo's group. The server knows about live photos and bursts; we do not
|
||||
/// have to guess at them.
|
||||
/// 2. Otherwise, same capture day **and** same file-name stem **and** one of the
|
||||
/// two is a camera raw while the other is not. That is the RAW+JPEG pair a
|
||||
/// camera writes, and the differing-kind clause keeps two JPEGs that happen
|
||||
/// to share a name apart.
|
||||
/// 3. Otherwise the photo is its own group.
|
||||
///
|
||||
/// The representative is the non-raw member when the group has one — a JPEG
|
||||
/// decodes in milliseconds and is what the person expects to see — and the
|
||||
/// earliest member in server order otherwise.
|
||||
fn group_photos(entries: &[Grouped]) -> Vec<String> {
|
||||
let mut parent: Vec<usize> = (0..entries.len()).collect();
|
||||
fn find(parent: &mut [usize], mut i: usize) -> usize {
|
||||
while parent[i] != i {
|
||||
parent[i] = parent[parent[i]];
|
||||
i = parent[i];
|
||||
}
|
||||
i
|
||||
}
|
||||
let union = |parent: &mut [usize], a: usize, b: usize| {
|
||||
let (a, b) = (find(parent, a), find(parent, b));
|
||||
if a != b {
|
||||
parent[b] = a;
|
||||
}
|
||||
};
|
||||
|
||||
let index: HashMap<&str, usize> = entries
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(i, e)| (e.uid.as_str(), i))
|
||||
.collect();
|
||||
for (i, entry) in entries.iter().enumerate() {
|
||||
if let Some(main) = entry.main_uid.as_deref()
|
||||
&& let Some(&j) = index.get(main)
|
||||
{
|
||||
union(&mut parent, j, i);
|
||||
}
|
||||
}
|
||||
|
||||
// Rule 2 needs only one pass: everything sharing a day and a stem lands in
|
||||
// the same bucket, and the raw / non-raw split is checked pairwise there.
|
||||
let mut by_name: HashMap<(&str, &str), Vec<usize>> = HashMap::new();
|
||||
for (i, entry) in entries.iter().enumerate() {
|
||||
if let (Some(day), Some(stem)) = (entry.day.as_deref(), entry.stem.as_deref()) {
|
||||
by_name.entry((day, stem)).or_default().push(i);
|
||||
}
|
||||
}
|
||||
let is_raw = |i: usize| entries[i].kind == crate::control::PhotoKind::Raw;
|
||||
for bucket in by_name.values() {
|
||||
for (n, &i) in bucket.iter().enumerate() {
|
||||
for &j in &bucket[n + 1..] {
|
||||
if is_raw(i) != is_raw(j) {
|
||||
union(&mut parent, i, j);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Representative per root, then the key every member carries.
|
||||
let mut representative: HashMap<usize, usize> = HashMap::new();
|
||||
for i in 0..entries.len() {
|
||||
let root = find(&mut parent, i);
|
||||
match representative.get(&root).copied() {
|
||||
Some(current) if !is_raw(current) || is_raw(i) => {}
|
||||
_ => {
|
||||
representative.insert(root, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
(0..entries.len())
|
||||
.map(|i| {
|
||||
let root = find(&mut parent, i);
|
||||
entries[representative[&root]].uid.clone()
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// The columns every photo read selects, with the group aggregates joined in.
|
||||
/// `g.n` is how many photos the group holds and `g.raw` whether any of them is a
|
||||
/// camera raw file — one query rather than a second lookup per tile.
|
||||
@@ -278,15 +151,286 @@ fn stored_photo(r: &rusqlite::Row<'_>) -> rusqlite::Result<StoredPhoto> {
|
||||
})
|
||||
}
|
||||
|
||||
const PHOTOS_GENERATION: &str = "photos_projection_generation";
|
||||
const PHOTOS_SYNCED: &str = "photos_synced_ms";
|
||||
const PHOTOS_AVAILABLE: &str = "photos_available";
|
||||
const PHOTOS_RECONCILE: &str = "photos_reconcile";
|
||||
|
||||
pub(super) fn photos_generation(conn: &Connection) -> rusqlite::Result<i64> {
|
||||
conn.query_row(
|
||||
"SELECT coalesce((SELECT CAST(value AS INTEGER) FROM sync_state WHERE key=?1),0)",
|
||||
[PHOTOS_GENERATION],
|
||||
|row| row.get(0),
|
||||
)
|
||||
}
|
||||
|
||||
pub(super) fn gallery_state(
|
||||
conn: &Connection,
|
||||
key: &str,
|
||||
value: impl rusqlite::ToSql,
|
||||
) -> rusqlite::Result<()> {
|
||||
conn.execute(
|
||||
"INSERT INTO sync_state(key,value) VALUES (?1,?2)
|
||||
ON CONFLICT(key) DO UPDATE SET value=excluded.value",
|
||||
params![key, value],
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn photos_delete_tx(tx: &Transaction<'_>, uids: &[String]) -> Result<usize> {
|
||||
let mut removed = 0;
|
||||
for uid in uids {
|
||||
tx.execute(
|
||||
"INSERT OR IGNORE INTO photo_tombstones(uid) VALUES (?1)",
|
||||
[uid],
|
||||
)?;
|
||||
removed += tx.execute("DELETE FROM photos WHERE uid=?1", [uid])?;
|
||||
tx.execute("DELETE FROM albums WHERE uid=?1", [uid])?;
|
||||
tx.execute("DELETE FROM album_photos WHERE album_uid=?1", [uid])?;
|
||||
tx.execute(
|
||||
"UPDATE albums SET photo_count=max(photo_count-1,0)
|
||||
WHERE cover_uid=?1 OR uid IN (SELECT album_uid FROM album_photos WHERE uid=?1)",
|
||||
[uid],
|
||||
)?;
|
||||
tx.execute("DELETE FROM album_photos WHERE uid=?1", [uid])?;
|
||||
tx.execute(
|
||||
"UPDATE albums SET cover_uid=(SELECT uid FROM album_photos
|
||||
WHERE album_uid=albums.uid ORDER BY seq LIMIT 1) WHERE cover_uid=?1",
|
||||
[uid],
|
||||
)?;
|
||||
}
|
||||
tx.execute(
|
||||
"UPDATE photos SET group_key=NULL WHERE group_key IS NOT NULL
|
||||
AND group_key NOT IN (SELECT uid FROM photos)",
|
||||
[],
|
||||
)?;
|
||||
Ok(removed)
|
||||
}
|
||||
|
||||
impl Db {
|
||||
pub fn photo_projection_generation(&self) -> Result<i64> {
|
||||
Ok(photos_generation(&self.read())?)
|
||||
}
|
||||
|
||||
/// One transaction records the deletion, stale metadata, listing work and feed position.
|
||||
pub fn photos_apply_events(
|
||||
&self,
|
||||
cursor_key: &str,
|
||||
cursor: &str,
|
||||
gone: &[String],
|
||||
touched: &[String],
|
||||
gap: bool,
|
||||
seed: bool,
|
||||
) -> Result<()> {
|
||||
let mut conn = self.conn.lock();
|
||||
let tx = conn.transaction()?;
|
||||
if !gone.is_empty() {
|
||||
photos_delete_tx(&tx, gone)?;
|
||||
}
|
||||
for uid in touched {
|
||||
tx.execute("DELETE FROM photo_tombstones WHERE uid=?1", [uid])?;
|
||||
tx.execute("UPDATE photos SET resolved_at=NULL WHERE uid=?1", [uid])?;
|
||||
tx.execute("UPDATE album_photos SET resolved=0 WHERE uid=?1", [uid])?;
|
||||
}
|
||||
if gap {
|
||||
tx.execute("UPDATE photos SET resolved_at=NULL", [])?;
|
||||
tx.execute("UPDATE album_photos SET resolved=0", [])?;
|
||||
gallery_state(&tx, PHOTOS_RECONCILE, 1)?;
|
||||
}
|
||||
if seed || gap || !gone.is_empty() || !touched.is_empty() {
|
||||
let generation = photos_generation(&tx)?;
|
||||
gallery_state(&tx, PHOTOS_GENERATION, generation + 1)?;
|
||||
tx.execute(
|
||||
"DELETE FROM sync_state WHERE key='albums_synced_ms'
|
||||
OR key GLOB 'album_synced_ms:*'",
|
||||
[],
|
||||
)?;
|
||||
}
|
||||
if seed || gap || !touched.is_empty() {
|
||||
tx.execute("DELETE FROM sync_state WHERE key=?1", [PHOTOS_SYNCED])?;
|
||||
}
|
||||
gallery_state(&tx, cursor_key, cursor)?;
|
||||
tx.commit()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn photos_invalidate(&self) -> Result<()> {
|
||||
let mut conn = self.conn.lock();
|
||||
let tx = conn.transaction()?;
|
||||
let generation = photos_generation(&tx)?;
|
||||
gallery_state(&tx, PHOTOS_GENERATION, generation + 1)?;
|
||||
tx.execute("DELETE FROM sync_state WHERE key=?1", [PHOTOS_SYNCED])?;
|
||||
tx.commit()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn photos_need_work(&self) -> Result<bool> {
|
||||
let conn = self.read();
|
||||
Ok(conn.query_row(
|
||||
"SELECT NOT EXISTS(SELECT 1 FROM sync_state WHERE key=?1)
|
||||
OR EXISTS(SELECT 1 FROM photos WHERE resolved_at IS NULL)",
|
||||
[PHOTOS_SYNCED],
|
||||
|r| r.get(0),
|
||||
)?)
|
||||
}
|
||||
|
||||
pub fn photos_pending(&self) -> Result<Vec<String>> {
|
||||
let conn = self.read();
|
||||
let mut stmt =
|
||||
conn.prepare("SELECT uid FROM photos WHERE resolved_at IS NULL ORDER BY seq")?;
|
||||
Ok(stmt
|
||||
.query_map([], |r| r.get(0))?
|
||||
.collect::<rusqlite::Result<_>>()?)
|
||||
}
|
||||
|
||||
pub fn photo_removed(&self, uid: &str) -> Result<bool> {
|
||||
Ok(self.read().query_row(
|
||||
"SELECT EXISTS(SELECT 1 FROM photo_tombstones WHERE uid=?1)",
|
||||
[uid],
|
||||
|r| r.get(0),
|
||||
)?)
|
||||
}
|
||||
|
||||
pub fn photos_contains(&self, uid: &str, album: Option<&str>) -> Result<bool> {
|
||||
let conn = self.read();
|
||||
Ok(match album {
|
||||
Some(album) => conn.query_row(
|
||||
"SELECT EXISTS(SELECT 1 FROM album_photos WHERE album_uid=?1 AND uid=?2)",
|
||||
params![album, uid],
|
||||
|r| r.get(0),
|
||||
)?,
|
||||
None => conn.query_row(
|
||||
"SELECT EXISTS(SELECT 1 FROM photos WHERE uid=?1)
|
||||
OR EXISTS(SELECT 1 FROM album_photos WHERE uid=?1)",
|
||||
[uid],
|
||||
|r| r.get(0),
|
||||
)?,
|
||||
})
|
||||
}
|
||||
|
||||
/// Persist one enrichment batch. The generation check and UPDATE share the
|
||||
/// writer transaction with deletion, so a stale batch cannot restore a row.
|
||||
pub fn photos_resolve_at(&self, generation: i64, rows: &[TimelineRow]) -> Result<bool> {
|
||||
let mut conn = self.conn.lock();
|
||||
let tx = conn.transaction()?;
|
||||
if photos_generation(&tx)? != generation {
|
||||
return Ok(false);
|
||||
}
|
||||
{
|
||||
let mut update = tx.prepare(
|
||||
"UPDATE photos SET name=?2, media_type=?3, kind=?4, favorite=?5,
|
||||
similar_hash=CASE WHEN content_hash IS ?6 THEN similar_hash ELSE NULL END,
|
||||
content_hash=?6, main_uid=?7, latitude=?8, longitude=?9, place_id=?10,
|
||||
resolved_at=?11 WHERE uid=?1",
|
||||
)?;
|
||||
for row in rows.iter().filter(|row| row.resolved_at.is_some()) {
|
||||
let kind = crate::control::PhotoKind::classify(
|
||||
row.name.as_deref(),
|
||||
row.media_type.as_deref(),
|
||||
);
|
||||
update.execute(params![
|
||||
row.uid,
|
||||
row.name,
|
||||
row.media_type,
|
||||
kind.as_i64(),
|
||||
row.favorite.unwrap_or(false),
|
||||
row.content_hash,
|
||||
row.main_uid,
|
||||
row.location.map(|p| p.0),
|
||||
row.location.map(|p| p.1),
|
||||
row.location
|
||||
.and_then(|(lat, lon)| crate::places::nearest(lat, lon))
|
||||
.map(|city| city.id),
|
||||
row.resolved_at
|
||||
])?;
|
||||
}
|
||||
}
|
||||
if !rows.is_empty() {
|
||||
let (entries, existing): (Vec<_>, Vec<Option<String>>) = {
|
||||
let mut stmt = tx.prepare(
|
||||
"SELECT uid,kind,main_uid,strftime('%Y-%m-%d',capture_time,'unixepoch','localtime'),
|
||||
name,group_key FROM photos ORDER BY seq",
|
||||
)?;
|
||||
stmt.query_map([], |r| {
|
||||
let name: Option<String> = r.get(4)?;
|
||||
Ok((
|
||||
Grouped {
|
||||
uid: r.get(0)?,
|
||||
raw: crate::control::PhotoKind::from_i64(r.get(1)?)
|
||||
== crate::control::PhotoKind::Raw,
|
||||
main_uid: r.get(2)?,
|
||||
day: r.get(3)?,
|
||||
stem: name_stem(name.as_deref()),
|
||||
},
|
||||
r.get(5)?,
|
||||
))
|
||||
})?
|
||||
.collect::<rusqlite::Result<Vec<_>>>()?
|
||||
.into_iter()
|
||||
.unzip()
|
||||
};
|
||||
let mut update = tx.prepare("UPDATE photos SET group_key=?2 WHERE uid=?1")?;
|
||||
for ((entry, old), group) in entries.iter().zip(existing).zip(group_photos(&entries)) {
|
||||
if old.as_deref() != Some(group.as_str()) {
|
||||
update.execute(params![entry.uid, group])?;
|
||||
}
|
||||
}
|
||||
}
|
||||
tx.commit()?;
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
/// Replace the timeline wholesale. A row whose `resolved_at` is `Some` was
|
||||
/// read from the server in this pass, so its fields are taken as they are —
|
||||
/// a `None` there means the server no longer reports that value. A row whose
|
||||
/// `resolved_at` is `None` was skipped or failed to resolve, and keeps
|
||||
/// whatever is already stored rather than having it silently cleared.
|
||||
pub fn photos_replace(&self, items: &[TimelineRow]) -> Result<()> {
|
||||
self.photos_replace_impl(items, None).map(|_| ())
|
||||
}
|
||||
|
||||
pub fn photos_replace_at(
|
||||
&self,
|
||||
items: &[TimelineRow],
|
||||
generation: i64,
|
||||
available: bool,
|
||||
now: i64,
|
||||
) -> Result<bool> {
|
||||
self.photos_replace_impl(items, Some((generation, available, now)))
|
||||
}
|
||||
|
||||
fn photos_replace_impl(
|
||||
&self,
|
||||
items: &[TimelineRow],
|
||||
stamp: Option<(i64, bool, i64)>,
|
||||
) -> Result<bool> {
|
||||
let mut conn = self.conn.lock();
|
||||
let tx = conn.transaction()?;
|
||||
let mut tombstones = HashSet::new();
|
||||
if let Some((generation, _, _)) = stamp {
|
||||
if photos_generation(&tx)? != generation {
|
||||
return Ok(false);
|
||||
}
|
||||
let repairing = tx
|
||||
.query_row(
|
||||
"SELECT 1 FROM sync_state WHERE key=?1",
|
||||
[PHOTOS_RECONCILE],
|
||||
|_| Ok(()),
|
||||
)
|
||||
.optional()?
|
||||
.is_some();
|
||||
if repairing {
|
||||
let mut remove = tx.prepare("DELETE FROM photo_tombstones WHERE uid=?1")?;
|
||||
for row in items {
|
||||
remove.execute([&row.uid])?;
|
||||
}
|
||||
tx.execute("DELETE FROM sync_state WHERE key=?1", [PHOTOS_RECONCILE])?;
|
||||
}
|
||||
let mut stmt = tx.prepare("SELECT uid FROM photo_tombstones")?;
|
||||
tombstones = stmt
|
||||
.query_map([], |r| r.get::<_, String>(0))?
|
||||
.collect::<rusqlite::Result<_>>()?;
|
||||
}
|
||||
// `name` and `media_type` are learned-and-kept like the ratio and thumb
|
||||
// verdict: the timeline DTO carries only the uid and capture time, so the
|
||||
// daemon may not know them when it replaces the timeline — because the
|
||||
@@ -325,6 +469,7 @@ impl Db {
|
||||
// Everything the insert and the grouping need, resolved once per photo.
|
||||
let resolved: Vec<(&TimelineRow, Learned, crate::control::PhotoKind)> = items
|
||||
.iter()
|
||||
.filter(|row| !tombstones.contains(&row.uid))
|
||||
.map(|row| {
|
||||
let mut carried = learned.get(&row.uid).cloned().unwrap_or(Learned {
|
||||
thumb_state: THUMB_UNKNOWN,
|
||||
@@ -369,7 +514,7 @@ impl Db {
|
||||
.iter()
|
||||
.map(|(row, carried, kind)| Grouped {
|
||||
uid: row.uid.clone(),
|
||||
kind: *kind,
|
||||
raw: *kind == crate::control::PhotoKind::Raw,
|
||||
main_uid: carried.main_uid.clone(),
|
||||
day: capture_day(&tx, row.capture_time),
|
||||
stem: name_stem(carried.name.as_deref()),
|
||||
@@ -414,8 +559,12 @@ impl Db {
|
||||
])?;
|
||||
}
|
||||
}
|
||||
if let Some((_, available, now)) = stamp {
|
||||
gallery_state(&tx, PHOTOS_AVAILABLE, available as i64)?;
|
||||
gallery_state(&tx, PHOTOS_SYNCED, now)?;
|
||||
}
|
||||
tx.commit()?;
|
||||
Ok(())
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
/// The uids whose node metadata is already resolved, so a refresh can skip
|
||||
@@ -458,8 +607,16 @@ impl Db {
|
||||
/// refresh. For a continuity loss, where the daemon cannot know what it
|
||||
/// missed, and for an explicit `refresh photos --full`.
|
||||
pub fn photos_mark_all_unresolved(&self) -> Result<usize> {
|
||||
let conn = self.conn.lock();
|
||||
Ok(conn.execute("UPDATE photos SET resolved_at = NULL", [])?)
|
||||
let mut conn = self.conn.lock();
|
||||
let tx = conn.transaction()?;
|
||||
let marked = tx.execute("UPDATE photos SET resolved_at=NULL", [])?;
|
||||
tx.execute("UPDATE album_photos SET resolved=0", [])?;
|
||||
let generation = photos_generation(&tx)?;
|
||||
gallery_state(&tx, PHOTOS_GENERATION, generation + 1)?;
|
||||
gallery_state(&tx, PHOTOS_RECONCILE, 1)?;
|
||||
tx.execute("DELETE FROM sync_state WHERE key=?1", [PHOTOS_SYNCED])?;
|
||||
tx.commit()?;
|
||||
Ok(marked)
|
||||
}
|
||||
|
||||
/// Forget photos that have been trashed, so the gallery does not show them
|
||||
@@ -474,23 +631,9 @@ impl Db {
|
||||
}
|
||||
let mut conn = self.conn.lock();
|
||||
let tx = conn.transaction()?;
|
||||
let mut removed = 0;
|
||||
{
|
||||
let mut photos = tx.prepare("DELETE FROM photos WHERE uid = ?1")?;
|
||||
let mut albums = tx.prepare("DELETE FROM album_photos WHERE uid = ?1")?;
|
||||
for uid in uids {
|
||||
removed += photos.execute([uid])?;
|
||||
albums.execute([uid])?;
|
||||
}
|
||||
}
|
||||
// A group whose representative went is left pointing at nothing, which
|
||||
// drops its other files off every page. Make them stand alone until the
|
||||
// next refresh groups them again.
|
||||
tx.execute(
|
||||
"UPDATE photos SET group_key = NULL WHERE group_key IS NOT NULL \
|
||||
AND group_key NOT IN (SELECT uid FROM photos)",
|
||||
[],
|
||||
)?;
|
||||
let removed = photos_delete_tx(&tx, uids)?;
|
||||
let generation = photos_generation(&tx)?;
|
||||
gallery_state(&tx, PHOTOS_GENERATION, generation + 1)?;
|
||||
tx.commit()?;
|
||||
Ok(removed)
|
||||
}
|
||||
@@ -513,24 +656,42 @@ impl Db {
|
||||
range: Option<(i64, i64)>,
|
||||
favorites: bool,
|
||||
not_in_album: bool,
|
||||
) -> Result<Vec<StoredPhoto>> {
|
||||
self.photos_page_visible(offset, limit, kind, range, favorites, not_in_album, "[]")
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn photos_page_visible(
|
||||
&self,
|
||||
offset: usize,
|
||||
limit: usize,
|
||||
kind: Option<crate::control::PhotoKind>,
|
||||
range: Option<(i64, i64)>,
|
||||
favorites: bool,
|
||||
not_in_album: bool,
|
||||
excluded: &str,
|
||||
) -> Result<Vec<StoredPhoto>> {
|
||||
let conn = self.read();
|
||||
// Built up so any combination of the optional filters is one indexed
|
||||
// query rather than a statement per case.
|
||||
let mut sql = String::from(PHOTO_SELECT);
|
||||
let mut binds: Vec<i64> = Vec::new();
|
||||
let mut binds: Vec<rusqlite::types::Value> = Vec::new();
|
||||
let mut conds: Vec<String> = Vec::new();
|
||||
if excluded != "[]" {
|
||||
binds.push(excluded.to_owned().into());
|
||||
conds.push("p.uid NOT IN (SELECT value FROM json_each(?1))".to_owned());
|
||||
}
|
||||
if kind != Some(crate::control::PhotoKind::Raw) {
|
||||
conds.push("p.uid = COALESCE(p.group_key, p.uid)".to_string());
|
||||
}
|
||||
if let Some(k) = kind {
|
||||
binds.push(k.as_i64());
|
||||
binds.push((k.as_i64()).into());
|
||||
conds.push(format!("p.kind = ?{}", binds.len()));
|
||||
}
|
||||
if let Some((from, to)) = range {
|
||||
binds.push(from);
|
||||
binds.push((from).into());
|
||||
conds.push(format!("p.capture_time >= ?{}", binds.len()));
|
||||
binds.push(to);
|
||||
binds.push((to).into());
|
||||
conds.push(format!("p.capture_time < ?{}", binds.len()));
|
||||
}
|
||||
if favorites {
|
||||
@@ -549,9 +710,9 @@ impl Db {
|
||||
sql.push_str(" WHERE ");
|
||||
sql.push_str(&conds.join(" AND "));
|
||||
}
|
||||
binds.push(limit as i64);
|
||||
binds.push((limit as i64).into());
|
||||
let limit_pos = binds.len();
|
||||
binds.push(offset as i64);
|
||||
binds.push((offset as i64).into());
|
||||
let offset_pos = binds.len();
|
||||
sql.push_str(&format!(
|
||||
" ORDER BY p.seq LIMIT ?{limit_pos} OFFSET ?{offset_pos}"
|
||||
@@ -580,6 +741,25 @@ impl Db {
|
||||
Ok(rows)
|
||||
}
|
||||
|
||||
/// Include associated files so a public preview cannot reveal a hidden
|
||||
/// RAW, JPEG or Live Photo through another part of the same shot.
|
||||
pub fn photo_group_members_for(&self, uids: &HashSet<String>) -> Result<HashSet<String>> {
|
||||
if uids.is_empty() {
|
||||
return Ok(HashSet::new());
|
||||
}
|
||||
let ids = serde_json::to_string(uids).expect("file identifiers serialize");
|
||||
let conn = self.read();
|
||||
let mut query = conn.prepare(
|
||||
"SELECT uid FROM photos WHERE COALESCE(group_key, uid) IN (
|
||||
SELECT COALESCE(group_key, uid) FROM photos
|
||||
WHERE uid IN (SELECT value FROM json_each(?1))
|
||||
)",
|
||||
)?;
|
||||
Ok(query
|
||||
.query_map([ids], |row| row.get(0))?
|
||||
.collect::<rusqlite::Result<_>>()?)
|
||||
}
|
||||
|
||||
/// The whole persisted timeline, in stored order — every file, not one row
|
||||
/// per group. Only for whole-library passes (the photo re-date); the gallery
|
||||
/// pages with [`Db::photos_page`].
|
||||
@@ -601,27 +781,38 @@ impl Db {
|
||||
pub fn photos_months(
|
||||
&self,
|
||||
kind: Option<crate::control::PhotoKind>,
|
||||
) -> Result<Vec<(i32, i32, usize)>> {
|
||||
self.photos_months_visible(kind, "[]")
|
||||
}
|
||||
|
||||
pub fn photos_months_visible(
|
||||
&self,
|
||||
kind: Option<crate::control::PhotoKind>,
|
||||
excluded: &str,
|
||||
) -> Result<Vec<(i32, i32, usize)>> {
|
||||
let conn = self.read();
|
||||
// The scrubber has to agree with the page it scrubs, so it counts what
|
||||
// the page shows: groups everywhere except on the Raw tab.
|
||||
let (filter, binds): (&str, Vec<i64>) = match kind {
|
||||
Some(crate::control::PhotoKind::Raw) => (" WHERE kind = 2", Vec::new()),
|
||||
Some(k) => (
|
||||
" WHERE uid = COALESCE(group_key, uid) AND kind = ?1",
|
||||
vec![k.as_i64()],
|
||||
),
|
||||
None => (" WHERE uid = COALESCE(group_key, uid)", Vec::new()),
|
||||
let filter = match kind {
|
||||
Some(crate::control::PhotoKind::Raw) => "kind = ?2",
|
||||
Some(_) => "uid = COALESCE(group_key, uid) AND kind = ?2",
|
||||
None => "uid = COALESCE(group_key, uid) AND ?2 IS NULL",
|
||||
};
|
||||
let sql = format!(
|
||||
"SELECT CAST(strftime('%Y', capture_time, 'unixepoch', 'localtime') AS INTEGER) AS y, \
|
||||
"WITH hidden_groups AS (
|
||||
SELECT COALESCE(group_key, uid) FROM photos
|
||||
WHERE uid IN (SELECT value FROM json_each(?1))
|
||||
)
|
||||
SELECT CAST(strftime('%Y', capture_time, 'unixepoch', 'localtime') AS INTEGER) AS y, \
|
||||
CAST(strftime('%m', capture_time, 'unixepoch', 'localtime') AS INTEGER) AS m, \
|
||||
COUNT(*) \
|
||||
FROM photos{filter} GROUP BY y, m ORDER BY y DESC, m DESC"
|
||||
FROM photos WHERE {filter}
|
||||
AND COALESCE(group_key, uid) NOT IN (SELECT * FROM hidden_groups)
|
||||
GROUP BY y, m ORDER BY y DESC, m DESC"
|
||||
);
|
||||
let mut stmt = conn.prepare(&sql)?;
|
||||
let rows = stmt
|
||||
.query_map(rusqlite::params_from_iter(binds), |r| {
|
||||
.query_map(params![excluded, kind.map(|kind| kind.as_i64())], |r| {
|
||||
Ok((
|
||||
r.get::<_, i32>(0)?,
|
||||
r.get::<_, i32>(1)?,
|
||||
@@ -637,6 +828,15 @@ impl Db {
|
||||
/// pick the date, and its own year is left out, because today's photos are
|
||||
/// what the timeline already opens on. One row per group, like the timeline.
|
||||
pub fn photos_on_this_day(&self, today: i64, limit: usize) -> Result<Vec<StoredPhoto>> {
|
||||
self.photos_on_this_day_visible(today, limit, "[]")
|
||||
}
|
||||
|
||||
pub fn photos_on_this_day_visible(
|
||||
&self,
|
||||
today: i64,
|
||||
limit: usize,
|
||||
excluded: &str,
|
||||
) -> Result<Vec<StoredPhoto>> {
|
||||
let conn = self.read();
|
||||
let sql = format!(
|
||||
"{PHOTO_SELECT} WHERE p.uid = COALESCE(p.group_key, p.uid) \
|
||||
@@ -644,11 +844,12 @@ impl Db {
|
||||
= strftime('%m-%d', ?1, 'unixepoch', 'localtime') \
|
||||
AND strftime('%Y', p.capture_time, 'unixepoch', 'localtime') \
|
||||
< strftime('%Y', ?1, 'unixepoch', 'localtime') \
|
||||
AND p.uid NOT IN (SELECT value FROM json_each(?3))
|
||||
ORDER BY p.seq LIMIT ?2"
|
||||
);
|
||||
let mut stmt = conn.prepare(&sql)?;
|
||||
let rows = stmt
|
||||
.query_map(params![today, limit as i64], stored_photo)?
|
||||
.query_map(params![today, limit as i64, excluded], stored_photo)?
|
||||
.collect::<rusqlite::Result<_>>()?;
|
||||
Ok(rows)
|
||||
}
|
||||
@@ -657,6 +858,10 @@ impl Db {
|
||||
/// cover, most photographed first. Counted per group, like the timeline;
|
||||
/// photos without a location, or taken far from any town, are in none.
|
||||
pub fn photo_places(&self) -> Result<Vec<StoredPlace>> {
|
||||
self.photo_places_visible("[]")
|
||||
}
|
||||
|
||||
pub fn photo_places_visible(&self, excluded: &str) -> Result<Vec<StoredPlace>> {
|
||||
let rows: Vec<(u32, usize, String)> = {
|
||||
let conn = self.read();
|
||||
// SQLite fills the bare `uid` from the row `MIN(seq)` picked, which
|
||||
@@ -664,9 +869,10 @@ impl Db {
|
||||
let mut stmt = conn.prepare(
|
||||
"SELECT place_id, COUNT(*), uid, MIN(seq) FROM photos \
|
||||
WHERE uid = COALESCE(group_key, uid) AND place_id IS NOT NULL \
|
||||
AND uid NOT IN (SELECT value FROM json_each(?1))
|
||||
GROUP BY place_id ORDER BY COUNT(*) DESC, MIN(seq)",
|
||||
)?;
|
||||
stmt.query_map([], |r| {
|
||||
stmt.query_map([excluded], |r| {
|
||||
Ok((r.get(0)?, r.get::<_, i64>(1)? as usize, r.get(2)?))
|
||||
})?
|
||||
.collect::<rusqlite::Result<_>>()?
|
||||
@@ -695,15 +901,29 @@ impl Db {
|
||||
id: u32,
|
||||
offset: usize,
|
||||
limit: usize,
|
||||
) -> Result<Vec<StoredPhoto>> {
|
||||
self.photos_at_place_visible(id, offset, limit, "[]")
|
||||
}
|
||||
|
||||
pub fn photos_at_place_visible(
|
||||
&self,
|
||||
id: u32,
|
||||
offset: usize,
|
||||
limit: usize,
|
||||
excluded: &str,
|
||||
) -> Result<Vec<StoredPhoto>> {
|
||||
let conn = self.read();
|
||||
let sql = format!(
|
||||
"{PHOTO_SELECT} WHERE p.uid = COALESCE(p.group_key, p.uid) AND p.place_id = ?1 \
|
||||
"{PHOTO_SELECT} WHERE p.uid = COALESCE(p.group_key, p.uid) AND p.place_id = ?1
|
||||
AND p.uid NOT IN (SELECT value FROM json_each(?4))
|
||||
ORDER BY p.seq LIMIT ?2 OFFSET ?3"
|
||||
);
|
||||
let mut stmt = conn.prepare(&sql)?;
|
||||
let rows = stmt
|
||||
.query_map(params![id, limit as i64, offset as i64], stored_photo)?
|
||||
.query_map(
|
||||
params![id, limit as i64, offset as i64, excluded],
|
||||
stored_photo,
|
||||
)?
|
||||
.collect::<rusqlite::Result<_>>()?;
|
||||
Ok(rows)
|
||||
}
|
||||
@@ -884,6 +1104,10 @@ impl Db {
|
||||
|
||||
/// Per-tab counts for the Photos page subtitle: `(photos, videos, raw)`.
|
||||
pub fn photos_counts(&self) -> Result<(usize, usize, usize)> {
|
||||
self.photos_counts_visible("[]")
|
||||
}
|
||||
|
||||
pub fn photos_counts_visible(&self, excluded: &str) -> Result<(usize, usize, usize)> {
|
||||
use crate::control::PhotoKind;
|
||||
let conn = self.read();
|
||||
// Photos and Videos count groups — one shot is one entry, however many
|
||||
@@ -891,9 +1115,12 @@ impl Db {
|
||||
// them individually.
|
||||
let mut stmt = conn.prepare(
|
||||
"SELECT kind, COUNT(*) FROM photos \
|
||||
WHERE uid = COALESCE(group_key, uid) OR kind = 2 GROUP BY kind",
|
||||
WHERE (uid = COALESCE(group_key, uid) OR kind = 2)
|
||||
AND uid NOT IN (SELECT value FROM json_each(?1)) GROUP BY kind",
|
||||
)?;
|
||||
let rows = stmt.query_map([], |r| Ok((r.get::<_, i64>(0)?, r.get::<_, i64>(1)?)))?;
|
||||
let rows = stmt.query_map([excluded], |r| {
|
||||
Ok((r.get::<_, i64>(0)?, r.get::<_, i64>(1)?))
|
||||
})?;
|
||||
let (mut photos, mut videos, mut raw) = (0usize, 0usize, 0usize);
|
||||
for row in rows {
|
||||
let (kind, n) = row?;
|
||||
|
||||
@@ -337,6 +337,10 @@ fn places_group_photos_by_the_nearest_town() {
|
||||
.map(|p| p.uid)
|
||||
.collect();
|
||||
assert_eq!(berlin, ["b2", "b1-jpeg"]);
|
||||
let visible = db.photo_places_visible(r#"["b2","p1"]"#).unwrap();
|
||||
assert_eq!(visible.len(), 1);
|
||||
assert_eq!(visible[0].count, 1);
|
||||
assert_eq!(visible[0].cover.uid, "b1-jpeg");
|
||||
}
|
||||
|
||||
/// A town's photos come with where each was taken, one per RAW+JPEG shot.
|
||||
@@ -2740,15 +2744,34 @@ fn atomic_trash_replacement_returns_owned_blobs_after_commit() {
|
||||
#[test]
|
||||
fn a_queued_trash_holds_its_name_until_it_lands() {
|
||||
let db = Db::open_in_memory().unwrap();
|
||||
db.upsert_node(&file("held-name", "root", "report.txt", 1))
|
||||
.unwrap();
|
||||
let node = uid("held-name").to_string();
|
||||
assert!(!db.has_pending_trash_named("report.txt").unwrap());
|
||||
let root = uid("root").to_string();
|
||||
assert!(
|
||||
!db.has_pending_trash_named("report.txt", Some(&root))
|
||||
.unwrap()
|
||||
);
|
||||
|
||||
let (trash_id, _) = db.replace_ops_with_trash(&node, "report.txt", 1).unwrap();
|
||||
assert!(db.has_pending_trash_named("report.txt").unwrap());
|
||||
assert!(!db.has_pending_trash_named("other.txt").unwrap());
|
||||
assert!(
|
||||
db.has_pending_trash_named("report.txt", Some(&root))
|
||||
.unwrap()
|
||||
);
|
||||
assert!(
|
||||
!db.has_pending_trash_named("other.txt", Some(&root))
|
||||
.unwrap()
|
||||
);
|
||||
assert!(
|
||||
!db.has_pending_trash_named("report.txt", Some(&uid("other").to_string()))
|
||||
.unwrap()
|
||||
);
|
||||
|
||||
db.delete_op(trash_id).unwrap();
|
||||
assert!(!db.has_pending_trash_named("report.txt").unwrap());
|
||||
assert!(
|
||||
!db.has_pending_trash_named("report.txt", Some(&root))
|
||||
.unwrap()
|
||||
);
|
||||
}
|
||||
|
||||
/// A create that found its name held by a queued trash backed off. The trash
|
||||
@@ -6094,7 +6117,7 @@ fn cache_eviction_candidates_are_lru_ordered_and_limited() {
|
||||
}
|
||||
db.cache_touch("other", "block", 100, 0).unwrap();
|
||||
|
||||
let batch = db.cache_eviction_candidates("blob", 3).unwrap();
|
||||
let batch = db.cache_eviction_candidates("blob", 3, 0).unwrap();
|
||||
assert_eq!(batch.len(), 3, "honours the limit");
|
||||
let keys: Vec<&str> = batch.iter().map(|(k, _)| k.as_str()).collect();
|
||||
assert_eq!(keys, ["k9", "k8", "k7"], "least-recently-accessed first");
|
||||
@@ -6925,6 +6948,54 @@ fn two_workers_never_share_a_node() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn trashing_a_folder_waits_for_moves_out_of_its_subtree() {
|
||||
let db = Db::open_in_memory().unwrap();
|
||||
db.upsert_nodes(&[
|
||||
folder("root", None, "My Files"),
|
||||
folder("source", Some("root"), "source"),
|
||||
folder("nested", Some("source"), "nested"),
|
||||
folder("destination", Some("root"), "destination"),
|
||||
file("photo", "destination", "photo.jpg", 1),
|
||||
])
|
||||
.unwrap();
|
||||
let source = uid("source").to_string();
|
||||
let destination = uid("destination").to_string();
|
||||
let (move_id, _) = db
|
||||
.enqueue_op(&PendingOp {
|
||||
kind: OP_RENAME.to_string(),
|
||||
uid: uid("photo").to_string(),
|
||||
parent_uid: Some(destination.clone()),
|
||||
name: Some("photo.jpg".into()),
|
||||
blob_path: None,
|
||||
meta_json: Some(
|
||||
serde_json::to_string(&RenameMeta {
|
||||
original_parent_uid: uid("nested").to_string(),
|
||||
original_name: Some("photo.jpg".into()),
|
||||
})
|
||||
.unwrap(),
|
||||
),
|
||||
next_attempt_at: 20,
|
||||
..bulk_op(0, &destination)
|
||||
})
|
||||
.unwrap();
|
||||
assert!(db.has_pending_moves_out_of(&source).unwrap());
|
||||
assert!(!db.has_pending_moves_out_of(&destination).unwrap());
|
||||
assert!(
|
||||
!db.has_pending_moves_out_of(&uid("root").to_string())
|
||||
.unwrap()
|
||||
);
|
||||
let (trash_id, _) = db.replace_ops_with_trash(&source, "source", 2).unwrap();
|
||||
|
||||
assert!(db.claim_next_due_op(10).unwrap().is_none());
|
||||
assert_eq!(db.earliest_due_at().unwrap(), Some(20));
|
||||
assert_eq!(db.claim_next_due_op(20).unwrap().unwrap().id, move_id);
|
||||
assert!(db.claim_next_due_op(20).unwrap().is_none());
|
||||
assert_eq!(db.earliest_due_at().unwrap(), None);
|
||||
db.delete_op(move_id).unwrap();
|
||||
assert_eq!(db.claim_next_due_op(20).unwrap().unwrap().id, trash_id);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn claims_do_not_survive_the_process_that_took_them() {
|
||||
let db = Db::open_in_memory().unwrap();
|
||||
@@ -7098,6 +7169,29 @@ fn a_raw_and_its_jpeg_are_one_entry_in_the_grid() {
|
||||
["jpeg", "raw"]
|
||||
);
|
||||
assert_eq!(db.photos_group("alone").unwrap().len(), 1);
|
||||
|
||||
let hidden = db
|
||||
.photo_group_members_for(&["raw".to_owned()].into_iter().collect())
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
hidden,
|
||||
["raw".to_owned(), "jpeg".to_owned()].into_iter().collect()
|
||||
);
|
||||
let excluded = serde_json::to_string(&hidden).unwrap();
|
||||
assert_eq!(db.photos_counts_visible(&excluded).unwrap(), (1, 0, 0));
|
||||
let months = db.photos_months_visible(None, &excluded).unwrap();
|
||||
assert_eq!(months.len(), 1);
|
||||
assert_eq!(months[0].2, 1);
|
||||
let public = db
|
||||
.photos_page_visible(0, 1, None, None, false, false, &excluded)
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
public
|
||||
.iter()
|
||||
.map(|photo| photo.uid.as_str())
|
||||
.collect::<Vec<_>>(),
|
||||
["alone"]
|
||||
);
|
||||
}
|
||||
|
||||
/// Pixel names the two files of one raw capture after the role each plays, so
|
||||
@@ -7778,3 +7872,87 @@ fn migration_v45_keeps_existing_device_folders_and_location_ids() {
|
||||
db.migrate().unwrap();
|
||||
assert_eq!(db.mount_list().unwrap().len(), 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn photo_feed_failure_keeps_the_cursor_and_a_stale_listing_cannot_restore_deleted_rows() {
|
||||
let db = Db::open_in_memory().unwrap();
|
||||
let rows = vec![TimelineRow::new("gone", 200), TimelineRow::new("keep", 100)];
|
||||
db.photos_replace(&rows).unwrap();
|
||||
db.albums_replace(&[StoredAlbum {
|
||||
uid: "album".into(),
|
||||
name: "Test album".into(),
|
||||
photo_count: 2,
|
||||
cover_uid: Some("gone".into()),
|
||||
last_activity: None,
|
||||
shared: false,
|
||||
}])
|
||||
.unwrap();
|
||||
db.album_photos_replace(
|
||||
"album",
|
||||
&[
|
||||
("gone".into(), 200, None, None),
|
||||
("keep".into(), 100, None, None),
|
||||
],
|
||||
)
|
||||
.unwrap();
|
||||
db.set_state_str("photos-cursor-test", "old").unwrap();
|
||||
let stale = db.photo_projection_generation().unwrap();
|
||||
db.conn.lock().execute_batch(
|
||||
"CREATE TEMP TRIGGER reject_cursor BEFORE INSERT ON sync_state WHEN NEW.key='photos-cursor-test'
|
||||
BEGIN SELECT RAISE(ABORT, 'simulated cursor failure'); END;",
|
||||
).unwrap();
|
||||
|
||||
let gone = ["gone".into()];
|
||||
assert!(
|
||||
db.photos_apply_events("photos-cursor-test", "next", &gone, &[], false, false)
|
||||
.is_err()
|
||||
);
|
||||
assert_eq!(
|
||||
db.state_str("photos-cursor-test").unwrap().as_deref(),
|
||||
Some("old")
|
||||
);
|
||||
assert_eq!(db.photos_count().unwrap(), 2);
|
||||
assert!(db.photos_contains("gone", Some("album")).unwrap());
|
||||
db.conn
|
||||
.lock()
|
||||
.execute("DROP TRIGGER reject_cursor", [])
|
||||
.unwrap();
|
||||
|
||||
db.photos_apply_events("photos-cursor-test", "next", &gone, &[], false, false)
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
db.state_str("photos-cursor-test").unwrap().as_deref(),
|
||||
Some("next")
|
||||
);
|
||||
assert!(!db.photos_contains("gone", None).unwrap());
|
||||
assert_eq!(
|
||||
db.albums_list().unwrap()[0].cover_uid.as_deref(),
|
||||
Some("keep")
|
||||
);
|
||||
assert!(!db.photos_replace_at(&rows, stale, true, 1).unwrap());
|
||||
assert!(
|
||||
!db.album_photos_replace_at("album", &[("gone".into(), 200, None, None)], stale, 1)
|
||||
.unwrap()
|
||||
);
|
||||
assert!(!db.photos_contains("gone", None).unwrap());
|
||||
|
||||
db.photos_apply_events("photos-cursor-test", "restore", &[], &gone, false, false)
|
||||
.unwrap();
|
||||
let current = db.photo_projection_generation().unwrap();
|
||||
assert!(db.photos_replace_at(&rows, current, true, 2).unwrap());
|
||||
assert!(db.photos_contains("gone", None).unwrap());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn warm_photo_months_exclude_hidden_groups_with_thirteen_thousand_rows() {
|
||||
let db = Db::open_in_memory().unwrap();
|
||||
let mut rows: Vec<_> = (0..13_000)
|
||||
.map(|i| TimelineRow::new(format!("volume~{i}"), 1_700_000_000 + i))
|
||||
.collect();
|
||||
rows[1].main_uid = Some(rows[0].uid.clone());
|
||||
db.photos_replace(&rows).unwrap();
|
||||
let started = std::time::Instant::now();
|
||||
let months = db.photos_months_visible(None, r#"["volume~1"]"#).unwrap();
|
||||
assert_eq!(months.iter().map(|month| month.2).sum::<usize>(), 12_998);
|
||||
assert!(started.elapsed() < std::time::Duration::from_secs(1));
|
||||
}
|
||||
@@ -347,6 +347,15 @@ pub fn sign_in_blocked(e: &proton_sdk::ProtonError) -> bool {
|
||||
/// The result every request-serving method in the daemon returns.
|
||||
pub type CoreResult<T> = std::result::Result<T, CoreError>;
|
||||
|
||||
impl From<proton_auth_rs::Error> for Error {
|
||||
fn from(error: proton_auth_rs::Error) -> Self {
|
||||
match error {
|
||||
proton_auth_rs::Error::Keyring(error) => Self::Keyring(error),
|
||||
other => Self::Other(other.to_string()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
@@ -1,133 +0,0 @@
|
||||
//! When a photo was taken, as its own EXIF tags say.
|
||||
//!
|
||||
//! The fallback for a photo nothing else dates: a Takeout photo without a
|
||||
//! sidecar or a date in its name, and a photo uploaded from the app. Without
|
||||
//! it the first was filed under the moment of the import and the second under
|
||||
//! the file's modification time, which a copy resets.
|
||||
|
||||
use std::io::{BufRead, Seek};
|
||||
use std::path::Path;
|
||||
|
||||
use crate::takeout::days_from_civil;
|
||||
|
||||
/// The capture time in the EXIF of the file at `path`, in epoch seconds.
|
||||
pub fn capture_time_of(path: &Path) -> Option<i64> {
|
||||
let file = std::fs::File::open(path).ok()?;
|
||||
capture_time(&mut std::io::BufReader::new(file))
|
||||
}
|
||||
|
||||
/// The capture time in the EXIF `reader` holds: `DateTimeOriginal`, then
|
||||
/// `DateTimeDigitized`, each adjusted by its `OffsetTime…` tag when the camera
|
||||
/// wrote one. Without an offset the time is read as UTC, as a date in a file
|
||||
/// name is (`takeout::capture_time_from_name`).
|
||||
pub fn capture_time(reader: &mut (impl BufRead + Seek)) -> Option<i64> {
|
||||
let exif = exif::Reader::new().read_from_container(reader).ok()?;
|
||||
let ascii = |tag: exif::Tag| -> Option<String> {
|
||||
let field = exif.get_field(tag, exif::In::PRIMARY)?;
|
||||
match &field.value {
|
||||
exif::Value::Ascii(parts) => parts.first().map(|part| {
|
||||
String::from_utf8_lossy(part)
|
||||
.trim_matches('\0')
|
||||
.trim()
|
||||
.to_string()
|
||||
}),
|
||||
_ => None,
|
||||
}
|
||||
};
|
||||
[
|
||||
(exif::Tag::DateTimeOriginal, exif::Tag::OffsetTimeOriginal),
|
||||
(exif::Tag::DateTimeDigitized, exif::Tag::OffsetTimeDigitized),
|
||||
]
|
||||
.into_iter()
|
||||
.find_map(|(time, offset)| {
|
||||
let local = parse_exif_time(&ascii(time)?)?;
|
||||
let offset = ascii(offset).and_then(|o| parse_offset(&o)).unwrap_or(0);
|
||||
Some(local - offset)
|
||||
})
|
||||
}
|
||||
|
||||
/// `YYYY:MM:DD HH:MM:SS` as epoch seconds, read as UTC. `None` for the
|
||||
/// all-zero or blank value cameras write when they do not know.
|
||||
fn parse_exif_time(text: &str) -> Option<i64> {
|
||||
let bytes = text.as_bytes();
|
||||
if bytes.len() < 19 || bytes[4] != b':' || bytes[7] != b':' || bytes[13] != b':' {
|
||||
return None;
|
||||
}
|
||||
let number = |range: std::ops::Range<usize>| text.get(range)?.parse::<i64>().ok();
|
||||
let (year, month, day) = (number(0..4)?, number(5..7)?, number(8..10)?);
|
||||
let (hour, minute, second) = (number(11..13)?, number(14..16)?, number(17..19)?);
|
||||
if !(1800..=9999).contains(&year)
|
||||
|| !(1..=12).contains(&month)
|
||||
|| !(1..=31).contains(&day)
|
||||
|| hour > 23
|
||||
|| minute > 59
|
||||
|| second > 60
|
||||
{
|
||||
return None;
|
||||
}
|
||||
Some(days_from_civil(year, month, day) * 86_400 + hour * 3600 + minute * 60 + second)
|
||||
}
|
||||
|
||||
/// `+HH:MM` or `-HH:MM` as seconds east of UTC.
|
||||
fn parse_offset(text: &str) -> Option<i64> {
|
||||
let sign = match text.as_bytes().first()? {
|
||||
b'+' => 1,
|
||||
b'-' => -1,
|
||||
_ => return None,
|
||||
};
|
||||
let (hours, minutes) = text.get(1..)?.split_once(':')?;
|
||||
let (hours, minutes) = (hours.parse::<i64>().ok()?, minutes.parse::<i64>().ok()?);
|
||||
(hours <= 14 && minutes < 60).then_some(sign * (hours * 3600 + minutes * 60))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn an_exif_time_reads_as_utc_and_its_offset_moves_it() {
|
||||
// 2023-06-01 12:00:00 UTC.
|
||||
let noon = 1_685_620_800;
|
||||
assert_eq!(parse_exif_time("2023:06:01 12:00:00"), Some(noon));
|
||||
assert_eq!(parse_offset("+02:00"), Some(7200));
|
||||
assert_eq!(parse_offset("-05:30"), Some(-19_800));
|
||||
assert_eq!(
|
||||
parse_exif_time("2023:06:01 14:00:00").map(|t| t - parse_offset("+02:00").unwrap()),
|
||||
Some(noon)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_unknown_exif_time_is_no_time() {
|
||||
assert_eq!(parse_exif_time("0000:00:00 00:00:00"), None);
|
||||
assert_eq!(parse_exif_time(" : : : : "), None);
|
||||
assert_eq!(parse_exif_time(""), None);
|
||||
assert_eq!(parse_offset("02:00"), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_photo_is_dated_by_its_original_time_and_offset() {
|
||||
let ascii = |tag, text: &str| exif::Field {
|
||||
tag,
|
||||
ifd_num: exif::In::PRIMARY,
|
||||
value: exif::Value::Ascii(vec![text.as_bytes().to_vec()]),
|
||||
};
|
||||
let taken = ascii(exif::Tag::DateTimeOriginal, "2023:06:01 14:00:00");
|
||||
let offset = ascii(exif::Tag::OffsetTimeOriginal, "+02:00");
|
||||
let digitized = ascii(exif::Tag::DateTimeDigitized, "2024:01:01 00:00:00");
|
||||
let mut writer = exif::experimental::Writer::new();
|
||||
writer.push_field(&taken);
|
||||
writer.push_field(&offset);
|
||||
writer.push_field(&digitized);
|
||||
let mut tiff = std::io::Cursor::new(Vec::new());
|
||||
writer.write(&mut tiff, false).unwrap();
|
||||
tiff.set_position(0);
|
||||
assert_eq!(capture_time(&mut tiff), Some(1_685_620_800));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_file_without_exif_has_no_capture_time() {
|
||||
let mut png = std::io::Cursor::new(b"\x89PNG\r\n\x1a\n".to_vec());
|
||||
assert_eq!(capture_time(&mut png), None);
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,6 @@ pub mod config;
|
||||
pub mod control;
|
||||
pub mod db;
|
||||
pub mod error;
|
||||
pub mod exiftime;
|
||||
pub mod kernelkey;
|
||||
pub mod keycheck;
|
||||
pub mod localindex;
|
||||
@@ -19,20 +18,20 @@ pub mod mountfail;
|
||||
pub mod mountpoint;
|
||||
pub mod mounts;
|
||||
pub mod opener;
|
||||
pub mod places;
|
||||
pub mod profile;
|
||||
pub mod sdkcache;
|
||||
pub mod search;
|
||||
pub mod service;
|
||||
pub mod shell;
|
||||
pub mod similar;
|
||||
pub mod syncignore;
|
||||
pub mod syncroot;
|
||||
pub mod takeout;
|
||||
pub mod timestamp;
|
||||
pub mod tray;
|
||||
pub mod update;
|
||||
|
||||
// Photo logic shared with Proton Gallery through the proton-rs crates.
|
||||
pub use proton_gallery_rs::{exiftime, places, similar, takeout};
|
||||
|
||||
pub use access::{Access, access_for, perm_bits};
|
||||
pub use error::{CoreError, CoreResult, Error, Result};
|
||||
|
||||
|
||||
@@ -40,9 +40,7 @@ pub fn path(state_dir: &Path) -> PathBuf {
|
||||
/// and renamed, so a reader never sees half of it.
|
||||
pub fn record(state_dir: &Path, failure: &MountFailure) -> std::io::Result<()> {
|
||||
let json = serde_json::to_vec(failure).map_err(std::io::Error::other)?;
|
||||
let tmp = state_dir.join(format!("{FILE_NAME}.tmp"));
|
||||
std::fs::write(&tmp, json)?;
|
||||
std::fs::rename(&tmp, path(state_dir))
|
||||
proton_base_rs::atomic::write_with_mode(&path(state_dir), &json, 0o644)
|
||||
}
|
||||
|
||||
/// Forget the failure: a mount is up, or a new daemon has started.
|
||||
|
||||
@@ -206,26 +206,23 @@ pub fn reap(mut child: std::process::Child) {
|
||||
});
|
||||
}
|
||||
|
||||
/// [`open`] with the policy from the user's `config.json`, read once per
|
||||
/// process. For callers that open the occasional path and have no reason to
|
||||
/// carry a policy around; long-lived windows should hold their own copy.
|
||||
/// [`open`] with the policy from the user's `config.json`, read again on
|
||||
/// every call: the file is small, a path is opened by hand, and a rule changed
|
||||
/// in Preferences then applies to the next file opened, without a restart.
|
||||
pub fn open_default(path: &Path, is_dir: bool) {
|
||||
open(default_policy(), path, is_dir);
|
||||
open(&default_policy(), path, is_dir);
|
||||
}
|
||||
|
||||
/// [`open_default`] matching the rules against `name` — see
|
||||
/// [`OpenWith::command_for_named`].
|
||||
pub fn open_default_named(path: &Path, name: &str, is_dir: bool) {
|
||||
open_named(default_policy(), path, name, is_dir);
|
||||
open_named(&default_policy(), path, name, is_dir);
|
||||
}
|
||||
|
||||
fn default_policy() -> &'static OpenWith {
|
||||
static POLICY: std::sync::OnceLock<OpenWith> = std::sync::OnceLock::new();
|
||||
POLICY.get_or_init(|| {
|
||||
crate::config::AppDirs::new()
|
||||
.map(|dirs| dirs.load_config().resolved_open_with())
|
||||
.unwrap_or_default()
|
||||
})
|
||||
fn default_policy() -> OpenWith {
|
||||
crate::config::AppDirs::new()
|
||||
.map(|dirs| dirs.load_config().resolved_open_with())
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
/// `$PDFS_TERMINAL`, then `$TERMINAL`, then the first [`KNOWN_TERMINALS`] entry
|
||||
@@ -266,6 +263,33 @@ fn with_exec_flag(program: &str) -> Vec<String> {
|
||||
argv
|
||||
}
|
||||
|
||||
/// Split a command line typed by the user into argv, the way a shell would:
|
||||
/// quotes keep spaces, nothing is expanded. `None` for an unclosed quote.
|
||||
pub fn parse_command(line: &str) -> Option<Vec<String>> {
|
||||
shell_words::split(line).ok()
|
||||
}
|
||||
|
||||
/// Show `argv` as one line that [`parse_command`] turns back into it.
|
||||
pub fn format_command(argv: &[String]) -> String {
|
||||
shell_words::join(argv)
|
||||
}
|
||||
|
||||
/// Whether the program `argv` starts with can be found: an absolute or
|
||||
/// relative path to a file, or a name on `PATH`. A `$VAR` program counts as
|
||||
/// found, since it is looked up only when a file is opened.
|
||||
pub fn command_available(argv: &[String]) -> bool {
|
||||
let Some(program) = argv.first() else {
|
||||
return false;
|
||||
};
|
||||
if program.starts_with('$') {
|
||||
return true;
|
||||
}
|
||||
if program.contains('/') {
|
||||
return Path::new(program).is_file();
|
||||
}
|
||||
on_path(program)
|
||||
}
|
||||
|
||||
fn on_path(program: &str) -> bool {
|
||||
let Some(path) = std::env::var_os("PATH") else {
|
||||
return false;
|
||||
@@ -703,4 +727,24 @@ mod tests {
|
||||
// Unknown terminals get the near-universal `-e`.
|
||||
assert_eq!(with_exec_flag("mystery-term"), vec!["mystery-term", "-e"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_typed_command_line_round_trips() {
|
||||
let argv = parse_command("alacritty -e 'my editor' --flag").unwrap();
|
||||
assert_eq!(argv, ["alacritty", "-e", "my editor", "--flag"]);
|
||||
assert_eq!(parse_command(&format_command(&argv)).unwrap(), argv);
|
||||
assert_eq!(parse_command("nvim 'unclosed"), None);
|
||||
assert_eq!(parse_command(" ").unwrap(), Vec::<String>::new());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_command_is_available_when_its_program_is() {
|
||||
assert!(command_available(&["sh".to_string()]));
|
||||
assert!(command_available(&["$EDITOR".to_string()]));
|
||||
assert!(!command_available(&[]));
|
||||
assert!(!command_available(
|
||||
&["pdfs-no-such-program-xyz".to_string()]
|
||||
));
|
||||
assert!(!command_available(&["/nonexistent/program".to_string()]));
|
||||
}
|
||||
}
|
||||
@@ -1,185 +0,0 @@
|
||||
//! Offline reverse geocoding: the town a photo was taken in, from its GPS
|
||||
//! position, without asking any service.
|
||||
//!
|
||||
//! The towns are GeoNames' `cities15000` dump (every place with more than
|
||||
//! 15,000 people), trimmed to id, name, position and country in
|
||||
//! `data/cities15000.tsv` by `scripts/geonames-cities.py`. The script drops the
|
||||
//! parts of a city, such as Kreuzberg or "Paris 15 Vaugirard", so that a photo
|
||||
//! lands in the town people would name. GeoNames publishes the dump under
|
||||
//! CC BY 4.0, which is why the About dialog credits it.
|
||||
//!
|
||||
//! `data/countries.tsv` maps each country code to its ISO 3166-1 English name,
|
||||
//! as the `iso-codes` project spells it, so a front end can translate it
|
||||
//! through that project's `iso_3166-1` gettext domain.
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::sync::OnceLock;
|
||||
|
||||
/// How far from the nearest town a photo may be and still count as taken
|
||||
/// there, in km. Farther out (at sea, in the wilderness) it has no place.
|
||||
pub const MAX_DISTANCE_KM: f64 = 50.0;
|
||||
|
||||
/// Mean Earth radius in km, for the haversine distance.
|
||||
const EARTH_RADIUS_KM: f64 = 6371.0;
|
||||
|
||||
const CITIES: &str = include_str!("../data/cities15000.tsv");
|
||||
const COUNTRIES: &str = include_str!("../data/countries.tsv");
|
||||
|
||||
/// One town of the table.
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct City {
|
||||
/// The GeoNames id, stable across dumps.
|
||||
pub id: u32,
|
||||
pub name: &'static str,
|
||||
pub latitude: f64,
|
||||
pub longitude: f64,
|
||||
/// ISO 3166-1 alpha-2 country code.
|
||||
pub country: &'static str,
|
||||
}
|
||||
|
||||
/// The towns, and an index of them by whole-degree cell.
|
||||
struct Table {
|
||||
cities: Vec<City>,
|
||||
cells: HashMap<(i32, i32), Vec<usize>>,
|
||||
}
|
||||
|
||||
fn table() -> &'static Table {
|
||||
static TABLE: OnceLock<Table> = OnceLock::new();
|
||||
TABLE.get_or_init(|| {
|
||||
let cities: Vec<City> = CITIES.lines().filter_map(parse_city).collect();
|
||||
let mut cells: HashMap<(i32, i32), Vec<usize>> = HashMap::new();
|
||||
for (index, city) in cities.iter().enumerate() {
|
||||
cells
|
||||
.entry(cell(city.latitude, city.longitude))
|
||||
.or_default()
|
||||
.push(index);
|
||||
}
|
||||
Table { cities, cells }
|
||||
})
|
||||
}
|
||||
|
||||
fn parse_city(line: &'static str) -> Option<City> {
|
||||
let mut fields = line.split('\t');
|
||||
Some(City {
|
||||
id: fields.next()?.parse().ok()?,
|
||||
name: fields.next()?,
|
||||
latitude: fields.next()?.parse().ok()?,
|
||||
longitude: fields.next()?.parse().ok()?,
|
||||
country: fields.next()?,
|
||||
})
|
||||
}
|
||||
|
||||
fn cell(latitude: f64, longitude: f64) -> (i32, i32) {
|
||||
(latitude.floor() as i32, longitude.floor() as i32)
|
||||
}
|
||||
|
||||
/// Great-circle distance between two positions, in km.
|
||||
pub fn distance_km(a: (f64, f64), b: (f64, f64)) -> f64 {
|
||||
let (lat1, lat2) = (a.0.to_radians(), b.0.to_radians());
|
||||
let dlat = lat2 - lat1;
|
||||
let dlon = (b.1 - a.1).to_radians();
|
||||
let h = (dlat / 2.0).sin().powi(2) + lat1.cos() * lat2.cos() * (dlon / 2.0).sin().powi(2);
|
||||
2.0 * EARTH_RADIUS_KM * h.sqrt().min(1.0).asin()
|
||||
}
|
||||
|
||||
/// The town nearest to a position, if one lies within [`MAX_DISTANCE_KM`].
|
||||
pub fn nearest(latitude: f64, longitude: f64) -> Option<&'static City> {
|
||||
if !latitude.is_finite() || !longitude.is_finite() {
|
||||
return None;
|
||||
}
|
||||
let table = table();
|
||||
// A degree of latitude is about 111 km everywhere; a degree of longitude
|
||||
// shrinks towards the poles, so more cells are needed to cover the radius.
|
||||
let lat_span = (MAX_DISTANCE_KM / 111.0).ceil() as i32;
|
||||
let lon_span = {
|
||||
let scale = latitude.to_radians().cos().abs().max(0.01);
|
||||
((MAX_DISTANCE_KM / (111.0 * scale)).ceil() as i32).min(180)
|
||||
};
|
||||
let (row, column) = cell(latitude, longitude);
|
||||
let mut best: Option<(f64, &City)> = None;
|
||||
for dlat in -lat_span..=lat_span {
|
||||
for dlon in -lon_span..=lon_span {
|
||||
// Longitude wraps at the antimeridian: -181 is 179.
|
||||
let lon_cell = (column + dlon + 180).rem_euclid(360) - 180;
|
||||
let Some(indices) = table.cells.get(&(row + dlat, lon_cell)) else {
|
||||
continue;
|
||||
};
|
||||
for &index in indices {
|
||||
let city = &table.cities[index];
|
||||
let d = distance_km((latitude, longitude), (city.latitude, city.longitude));
|
||||
if d <= MAX_DISTANCE_KM && best.is_none_or(|(bd, _)| d < bd) {
|
||||
best = Some((d, city));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
best.map(|(_, city)| city)
|
||||
}
|
||||
|
||||
/// The town with this GeoNames id.
|
||||
pub fn city(id: u32) -> Option<&'static City> {
|
||||
let cities = &table().cities;
|
||||
// The table is sorted by id.
|
||||
cities
|
||||
.binary_search_by_key(&id, |city| city.id)
|
||||
.ok()
|
||||
.map(|index| &cities[index])
|
||||
}
|
||||
|
||||
/// The English ISO 3166-1 name of a country code, such as "Germany" for "DE".
|
||||
pub fn country_name(code: &str) -> Option<&'static str> {
|
||||
COUNTRIES.lines().find_map(|line| {
|
||||
let (c, name) = line.split_once('\t')?;
|
||||
(c == code).then_some(name)
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn a_position_in_a_town_resolves_to_that_town() {
|
||||
let berlin = nearest(52.52, 13.405).expect("Berlin is a town");
|
||||
assert_eq!(berlin.name, "Berlin");
|
||||
assert_eq!(berlin.country, "DE");
|
||||
assert_eq!(city(berlin.id), Some(berlin));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_open_sea_has_no_town() {
|
||||
assert_eq!(nearest(0.0, -30.0), None);
|
||||
assert_eq!(nearest(f64::NAN, 0.0), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_town_across_the_antimeridian_is_still_found() {
|
||||
// Just east of 180°, the nearest towns in Fiji are west of it.
|
||||
let town = nearest(-16.8, 179.99);
|
||||
assert!(town.is_none_or(|t| t.country == "FJ"));
|
||||
let suva = nearest(-18.14, 178.44).expect("Suva is a town");
|
||||
assert_eq!(suva.country, "FJ");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn every_town_has_a_named_country() {
|
||||
for city in &table().cities {
|
||||
assert!(
|
||||
country_name(city.country).is_some(),
|
||||
"{} has no country name for {}",
|
||||
city.name,
|
||||
city.country
|
||||
);
|
||||
}
|
||||
assert_eq!(country_name("DE"), Some("Germany"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn distances_are_great_circle_km() {
|
||||
let d = distance_km((52.52, 13.405), (48.137, 11.575));
|
||||
assert!(
|
||||
(d - 504.0).abs() < 5.0,
|
||||
"Berlin to Munich is about 504 km, got {d}"
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,193 +0,0 @@
|
||||
//! Telling photos apart by what they show rather than by their bytes.
|
||||
//!
|
||||
//! The server's content hash only matches byte-identical files. A photo that
|
||||
//! was resized, re-encoded or sent through a messenger is another file, so the
|
||||
//! similar-photo finder hashes each thumbnail instead: a 64-bit difference
|
||||
//! hash ("dHash"), which compares neighbouring brightness in a 9×8 grid. Two
|
||||
//! copies of one picture land a few bits apart, and different pictures about
|
||||
//! half of the bits apart.
|
||||
|
||||
/// Hashes this many bits apart or fewer show the same picture.
|
||||
pub const SIMILAR_BITS: u32 = 6;
|
||||
|
||||
/// Stored for a photo whose thumbnail was looked at and gave no usable hash
|
||||
/// (it couldn't be decoded, or is one flat colour), so it isn't looked at
|
||||
/// again. A real hash is never 0: a picture that would hash to 0 has no
|
||||
/// brightness changes, which [`difference_hash`] turns down as flat.
|
||||
pub const NO_HASH: u64 = 0;
|
||||
|
||||
/// Samples of the grid that differ by less than this in brightness, all of
|
||||
/// them, make a flat picture — a black frame, a blank page — whose hash is
|
||||
/// noise and would match every other flat picture.
|
||||
const FLAT: u8 = 8;
|
||||
|
||||
/// The difference hash of an 8-bit greyscale image `width` px wide, rows
|
||||
/// stored one after another in `luma`. `None` for an empty or flat image.
|
||||
pub fn difference_hash(width: usize, height: usize, luma: &[u8]) -> Option<u64> {
|
||||
if width == 0 || height == 0 || luma.len() < width * height {
|
||||
return None;
|
||||
}
|
||||
// Box-average down to 9×8, so every source pixel counts once and the hash
|
||||
// doesn't depend on which pixels a nearest-neighbour pick happens to hit.
|
||||
let mut grid = [[0u8; 9]; 8];
|
||||
for (gy, row) in grid.iter_mut().enumerate() {
|
||||
let (y0, y1) = span(gy, 8, height);
|
||||
for (gx, cell) in row.iter_mut().enumerate() {
|
||||
let (x0, x1) = span(gx, 9, width);
|
||||
let mut sum = 0u64;
|
||||
for y in y0..y1 {
|
||||
sum += luma[y * width + x0..y * width + x1]
|
||||
.iter()
|
||||
.map(|&v| u64::from(v))
|
||||
.sum::<u64>();
|
||||
}
|
||||
*cell = (sum / ((y1 - y0) * (x1 - x0)) as u64) as u8;
|
||||
}
|
||||
}
|
||||
let (min, max) = grid
|
||||
.iter()
|
||||
.flatten()
|
||||
.fold((u8::MAX, 0), |(min, max), &v| (min.min(v), max.max(v)));
|
||||
if max - min < FLAT {
|
||||
return None;
|
||||
}
|
||||
let mut hash = 0u64;
|
||||
for row in &grid {
|
||||
for pair in row.windows(2) {
|
||||
hash = hash << 1 | u64::from(pair[0] < pair[1]);
|
||||
}
|
||||
}
|
||||
(hash != NO_HASH).then_some(hash)
|
||||
}
|
||||
|
||||
/// The source pixels `from..to` that cell `i` of `cells` covers along an edge
|
||||
/// of `len` px; never empty, even for an edge shorter than the grid.
|
||||
fn span(i: usize, cells: usize, len: usize) -> (usize, usize) {
|
||||
let from = (i * len / cells).min(len - 1);
|
||||
let to = ((i + 1) * len / cells).max(from + 1);
|
||||
(from, to)
|
||||
}
|
||||
|
||||
/// Whether two hashes show the same picture.
|
||||
pub fn alike(a: u64, b: u64) -> bool {
|
||||
(a ^ b).count_ones() <= SIMILAR_BITS
|
||||
}
|
||||
|
||||
/// Group `hashes` into sets of alike ones, by index, each set in index order
|
||||
/// and the sets by their first index. A hash alike to none other is in no
|
||||
/// set. Alike is taken as catching: a burst of shots each a little different
|
||||
/// from the last is one set.
|
||||
pub fn sets(hashes: &[u64]) -> Vec<Vec<usize>> {
|
||||
// Two hashes at most SIMILAR_BITS apart agree on at least one of their
|
||||
// eight bytes, as long as SIMILAR_BITS < 8. So only hashes sharing some
|
||||
// byte are compared, not every pair of the library.
|
||||
const _: () = assert!(SIMILAR_BITS < 8);
|
||||
let mut parent: Vec<usize> = (0..hashes.len()).collect();
|
||||
fn root(parent: &mut [usize], mut i: usize) -> usize {
|
||||
while parent[i] != i {
|
||||
parent[i] = parent[parent[i]];
|
||||
i = parent[i];
|
||||
}
|
||||
i
|
||||
}
|
||||
for byte in 0..8 {
|
||||
let mut buckets: Vec<Vec<usize>> = vec![Vec::new(); 256];
|
||||
for (i, &hash) in hashes.iter().enumerate() {
|
||||
buckets[(hash >> (byte * 8)) as u8 as usize].push(i);
|
||||
}
|
||||
for bucket in &buckets {
|
||||
for (n, &a) in bucket.iter().enumerate() {
|
||||
for &b in &bucket[n + 1..] {
|
||||
if alike(hashes[a], hashes[b]) {
|
||||
let (ra, rb) = (root(&mut parent, a), root(&mut parent, b));
|
||||
if ra != rb {
|
||||
parent[ra.max(rb)] = ra.min(rb);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
let mut by_root: std::collections::BTreeMap<usize, Vec<usize>> = Default::default();
|
||||
for i in 0..hashes.len() {
|
||||
let r = root(&mut parent, i);
|
||||
by_root.entry(r).or_default().push(i);
|
||||
}
|
||||
by_root.into_values().filter(|set| set.len() > 1).collect()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
/// A 90×80 picture: a bright disc on a gradient.
|
||||
fn picture(width: usize, height: usize) -> Vec<u8> {
|
||||
let mut luma = Vec::with_capacity(width * height);
|
||||
for y in 0..height {
|
||||
for x in 0..width {
|
||||
let (fx, fy) = (x as f64 / width as f64, y as f64 / height as f64);
|
||||
let disc = ((fx - 0.3).powi(2) + (fy - 0.6).powi(2)).sqrt() < 0.2;
|
||||
let v = if disc { 240.0 } else { 40.0 + 120.0 * fx * fy };
|
||||
luma.push(v as u8);
|
||||
}
|
||||
}
|
||||
luma
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_resized_copy_hashes_alike() {
|
||||
let big = difference_hash(900, 800, &picture(900, 800)).unwrap();
|
||||
let small = difference_hash(91, 79, &picture(91, 79)).unwrap();
|
||||
assert!(
|
||||
alike(big, small),
|
||||
"{} bits apart",
|
||||
(big ^ small).count_ones()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_different_picture_hashes_apart() {
|
||||
let one = difference_hash(90, 80, &picture(90, 80)).unwrap();
|
||||
let mirrored: Vec<u8> = picture(90, 80)
|
||||
.chunks(90)
|
||||
.flat_map(|row| row.iter().rev().copied().collect::<Vec<_>>())
|
||||
.collect();
|
||||
let other = difference_hash(90, 80, &mirrored).unwrap();
|
||||
assert!(!alike(one, other));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_flat_picture_has_no_hash() {
|
||||
assert_eq!(difference_hash(64, 64, &[17; 64 * 64]), None);
|
||||
assert_eq!(difference_hash(0, 0, &[]), None);
|
||||
assert_eq!(difference_hash(4, 4, &[0; 3]), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_picture_smaller_than_the_grid_still_hashes() {
|
||||
let luma: Vec<u8> = (0..4 * 3).map(|i| (i * 20) as u8).collect();
|
||||
assert!(difference_hash(4, 3, &luma).is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn alike_hashes_form_sets_and_catch_on() {
|
||||
let a = 0x0123_4567_89ab_cdef_u64;
|
||||
let hashes = [
|
||||
a,
|
||||
!a,
|
||||
a ^ 0b111,
|
||||
a ^ 0b111 ^ (0b1111 << 40),
|
||||
0x5555_0000_ffff_aaaa,
|
||||
];
|
||||
assert_eq!(sets(&hashes), vec![vec![0, 2, 3]]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hashes_apart_in_most_bytes_are_still_found() {
|
||||
// One bit apart in each of six bytes: six bits in all, and only the
|
||||
// top two bytes agree.
|
||||
let a = 1u64 << 63;
|
||||
let b = (0..6).fold(a, |h, byte| h | 1 << (byte * 8));
|
||||
assert_eq!(sets(&[a, b]), vec![vec![0, 1]]);
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,11 @@ use ignore::gitignore::{Gitignore, GitignoreBuilder};
|
||||
/// them. Version-control metadata, dependency and build trees, editor
|
||||
/// leftovers, and OS turds — none of which belong on Drive, all of which are
|
||||
/// large or rewritten constantly.
|
||||
///
|
||||
/// The second half is what Nextcloud, Dropbox and Syncthing leave out as well:
|
||||
/// files a desktop, a file system or a program in the middle of a write leaves
|
||||
/// behind, never anything a person made. Every one is in a test, next to a real
|
||||
/// file of a similar name that must stay synced.
|
||||
pub const DEFAULT_IGNORE_PATTERNS: &[&str] = &[
|
||||
".git/",
|
||||
".hg/",
|
||||
@@ -43,6 +48,23 @@ pub const DEFAULT_IGNORE_PATTERNS: &[&str] = &[
|
||||
"*.tmp",
|
||||
".DS_Store",
|
||||
"Thumbs.db",
|
||||
// Folder settings of Windows and KDE's Dolphin.
|
||||
"desktop.ini",
|
||||
".directory",
|
||||
// Trash folders and file-system leftovers: a file deleted while open on a
|
||||
// FUSE or NFS mount lives on under one of these names until it is closed.
|
||||
".Trash-*/",
|
||||
".Trashes/",
|
||||
".Spotlight-V100/",
|
||||
".fuse_hidden*",
|
||||
".nfs*",
|
||||
// Downloads and saves still being written.
|
||||
"*.part",
|
||||
"*.crdownload",
|
||||
"*.kate-swp",
|
||||
// Office lock files: LibreOffice's `.~lock.<name>#`, Microsoft Office's `~$<name>`.
|
||||
".~lock.*#",
|
||||
"~$*",
|
||||
];
|
||||
|
||||
/// Suffixes that mean a file is incomplete *by construction*: only the program
|
||||
@@ -119,6 +141,225 @@ pub fn is_scratch_name(name: &str) -> bool {
|
||||
/// Filenames accepted as a folder's ignore file, in precedence order.
|
||||
const IGNORE_FILE_NAMES: &[&str] = &[".pdfsignore", ".protonignore"];
|
||||
|
||||
/// Whether `line` is a rule [`IgnoreRules::load`] accepts: a pattern, a
|
||||
/// comment or a blank line. The error says what is wrong with it.
|
||||
pub fn check_pattern(line: &str) -> Result<(), String> {
|
||||
GitignoreBuilder::new("/")
|
||||
.add_line(None, line)
|
||||
.map(|_| ())
|
||||
.map_err(|e| e.to_string())
|
||||
}
|
||||
|
||||
/// The lines of an ignore file that [`IgnoreRules::load`] would skip, by line
|
||||
/// number (from 1), with what is wrong with each.
|
||||
pub fn check_rules(text: &str) -> Vec<(usize, String)> {
|
||||
text.lines()
|
||||
.enumerate()
|
||||
.filter_map(|(i, line)| check_pattern(line).err().map(|e| (i + 1, e)))
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// A synced folder's own ignore file, read so it can be edited and written
|
||||
/// back. See [`FolderRules::read`].
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct FolderRules {
|
||||
/// The file the rules are in: the one in use, or `.pdfsignore` when there
|
||||
/// is none yet.
|
||||
pub path: std::path::PathBuf,
|
||||
/// The rules as read; empty when there is no file. `None` means there was
|
||||
/// no file, which [`write`](Self::write) checks is still so.
|
||||
pub text: Option<String>,
|
||||
}
|
||||
|
||||
/// Why [`FolderRules::write`] did not write.
|
||||
#[derive(Debug)]
|
||||
pub enum WriteRulesError {
|
||||
/// The file changed after it was read, for example by an edit on another
|
||||
/// computer that sync brought in. The rules on disk are the new ones.
|
||||
Changed,
|
||||
/// Reading or writing failed.
|
||||
Io(std::io::Error),
|
||||
}
|
||||
|
||||
impl std::fmt::Display for WriteRulesError {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::Changed => f.write_str("the file changed since it was opened"),
|
||||
Self::Io(e) => e.fmt(f),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::error::Error for WriteRulesError {}
|
||||
|
||||
impl From<std::io::Error> for WriteRulesError {
|
||||
fn from(e: std::io::Error) -> Self {
|
||||
Self::Io(e)
|
||||
}
|
||||
}
|
||||
|
||||
impl FolderRules {
|
||||
/// Read the ignore file of the folder at `root`, the same one
|
||||
/// [`IgnoreRules::load`] uses.
|
||||
pub fn read(root: &Path) -> std::io::Result<Self> {
|
||||
for name in IGNORE_FILE_NAMES {
|
||||
let path = root.join(name);
|
||||
match std::fs::read_to_string(&path) {
|
||||
Ok(text) => {
|
||||
return Ok(Self {
|
||||
path,
|
||||
text: Some(text),
|
||||
});
|
||||
}
|
||||
Err(e) if e.kind() == std::io::ErrorKind::NotFound => continue,
|
||||
Err(e) => return Err(e),
|
||||
}
|
||||
}
|
||||
// Like `load`, a missing folder reads as one without rules; the write
|
||||
// is what fails then.
|
||||
Ok(Self {
|
||||
path: root.join(IGNORE_FILE_NAMES[0]),
|
||||
text: None,
|
||||
})
|
||||
}
|
||||
|
||||
/// Replace the rules with `text`, unless the file changed since it was
|
||||
/// read. Rules that are all blank remove the file, so a folder never keeps
|
||||
/// an empty one around.
|
||||
///
|
||||
/// Written to a temporary file and renamed over the old one, so the sync
|
||||
/// pass reading the rules at the same moment sees the old ones or the new
|
||||
/// ones, never half of them.
|
||||
pub fn write(&self, text: &str) -> Result<(), WriteRulesError> {
|
||||
let now = match std::fs::read_to_string(&self.path) {
|
||||
Ok(now) => Some(now),
|
||||
Err(e) if e.kind() == std::io::ErrorKind::NotFound => None,
|
||||
Err(e) => return Err(e.into()),
|
||||
};
|
||||
if now != self.text {
|
||||
return Err(WriteRulesError::Changed);
|
||||
}
|
||||
if text.trim().is_empty() {
|
||||
return match std::fs::remove_file(&self.path) {
|
||||
Err(e) if e.kind() != std::io::ErrorKind::NotFound => Err(e.into()),
|
||||
_ => Ok(()),
|
||||
};
|
||||
}
|
||||
let Some(name) = self.path.file_name() else {
|
||||
return Err(std::io::Error::other("the rules path has no file name").into());
|
||||
};
|
||||
let mut tmp_name = std::ffi::OsString::from(".");
|
||||
tmp_name.push(name);
|
||||
tmp_name.push(format!(".tmp-{}", std::process::id()));
|
||||
let tmp = self.path.with_file_name(tmp_name);
|
||||
let mut body = text.to_string();
|
||||
if !body.ends_with('\n') {
|
||||
body.push('\n');
|
||||
}
|
||||
let written = std::fs::write(&tmp, body).and_then(|()| std::fs::rename(&tmp, &self.path));
|
||||
if written.is_err() {
|
||||
let _ = std::fs::remove_file(&tmp);
|
||||
}
|
||||
Ok(written?)
|
||||
}
|
||||
|
||||
/// The patterns in the rules: every line that is not blank or a comment,
|
||||
/// trimmed of surrounding white space.
|
||||
pub fn patterns(&self) -> Vec<&str> {
|
||||
self.text
|
||||
.as_deref()
|
||||
.unwrap_or_default()
|
||||
.lines()
|
||||
.map(str::trim)
|
||||
.filter(|line| !line.is_empty() && !line.starts_with('#'))
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
||||
/// How often [`add_folder_pattern`] and [`remove_folder_pattern`] read the
|
||||
/// rules again when they changed between the read and the write.
|
||||
const RULES_RETRIES: usize = 3;
|
||||
|
||||
/// Add `pattern` at the end of the own rules of the folder at `root`, keeping
|
||||
/// every other line and comment. Says whether it added it: a pattern already
|
||||
/// there is left alone.
|
||||
pub fn add_folder_pattern(root: &Path, pattern: &str) -> std::io::Result<bool> {
|
||||
let pattern = pattern.trim();
|
||||
edit_folder_rules(root, |rules| {
|
||||
if rules.patterns().contains(&pattern) {
|
||||
return None;
|
||||
}
|
||||
let mut text = rules.text.clone().unwrap_or_default();
|
||||
if !text.is_empty() && !text.ends_with('\n') {
|
||||
text.push('\n');
|
||||
}
|
||||
text.push_str(pattern);
|
||||
text.push('\n');
|
||||
Some(text)
|
||||
})
|
||||
}
|
||||
|
||||
/// Remove every line that is `pattern` from the own rules of the folder at
|
||||
/// `root`. Says whether there was one.
|
||||
pub fn remove_folder_pattern(root: &Path, pattern: &str) -> std::io::Result<bool> {
|
||||
let pattern = pattern.trim();
|
||||
edit_folder_rules(root, |rules| {
|
||||
if !rules.patterns().contains(&pattern) {
|
||||
return None;
|
||||
}
|
||||
let text = rules.text.as_deref().unwrap_or_default();
|
||||
Some(
|
||||
text.lines()
|
||||
.filter(|line| line.trim() != pattern)
|
||||
.map(|line| format!("{line}\n"))
|
||||
.collect(),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
/// Read the folder's rules, let `edit` return their new text (or `None` to
|
||||
/// leave them), and write it. Rules that changed in between, such as by sync
|
||||
/// bringing in an edit from another computer, are read again and edited anew.
|
||||
fn edit_folder_rules(
|
||||
root: &Path,
|
||||
edit: impl Fn(&FolderRules) -> Option<String>,
|
||||
) -> std::io::Result<bool> {
|
||||
for _ in 0..RULES_RETRIES {
|
||||
let rules = FolderRules::read(root)?;
|
||||
let Some(text) = edit(&rules) else {
|
||||
return Ok(false);
|
||||
};
|
||||
match rules.write(&text) {
|
||||
Ok(()) => return Ok(true),
|
||||
Err(WriteRulesError::Changed) => continue,
|
||||
Err(WriteRulesError::Io(e)) => return Err(e),
|
||||
}
|
||||
}
|
||||
Err(std::io::Error::other(
|
||||
"the rules kept changing while they were being saved",
|
||||
))
|
||||
}
|
||||
|
||||
/// Where a rule that decided about a path came from.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum RuleSource {
|
||||
/// The rules for every synced folder (`ignore_patterns`).
|
||||
AllFolders,
|
||||
/// The folder's own ignore file.
|
||||
ThisFolder,
|
||||
}
|
||||
|
||||
/// What the rules say about one path, and which rule says it.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum Verdict {
|
||||
/// No rule matches: the path is synced.
|
||||
Synced,
|
||||
/// Left out by `pattern`. `pattern` may name a folder the path is in.
|
||||
Excluded { pattern: String, source: RuleSource },
|
||||
/// A rule excluded it, and a later `!pattern` brought it back.
|
||||
Included { pattern: String, source: RuleSource },
|
||||
}
|
||||
|
||||
/// Compiled ignore rules for one synced folder.
|
||||
pub struct IgnoreRules {
|
||||
matcher: Option<Gitignore>,
|
||||
@@ -161,6 +402,27 @@ impl IgnoreRules {
|
||||
}
|
||||
}
|
||||
|
||||
/// [`load`](Self::load) with `text` standing in for the folder's ignore
|
||||
/// file, for showing what rules being edited would do before they are
|
||||
/// saved.
|
||||
pub fn with_folder_text(root: &Path, globals: &[String], text: &str) -> Self {
|
||||
let mut builder = GitignoreBuilder::new(root);
|
||||
let mut any = false;
|
||||
for pattern in globals {
|
||||
any |= builder.add_line(None, pattern).is_ok();
|
||||
}
|
||||
let file = root.join(IGNORE_FILE_NAMES[0]);
|
||||
for line in text.lines() {
|
||||
any |= builder.add_line(Some(file.clone()), line).is_ok();
|
||||
}
|
||||
if !any {
|
||||
return Self { matcher: None };
|
||||
}
|
||||
Self {
|
||||
matcher: builder.build().ok(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Rules matching nothing, for callers with no folder context.
|
||||
pub fn empty() -> Self {
|
||||
Self { matcher: None }
|
||||
@@ -207,6 +469,50 @@ impl IgnoreRules {
|
||||
}
|
||||
}
|
||||
|
||||
impl IgnoreRules {
|
||||
/// What the rules say about `rel`, and which rule decides, the way
|
||||
/// [`is_ignored`](Self::is_ignored) decides it.
|
||||
pub fn explain(&self, rel: &str, is_dir: bool) -> Verdict {
|
||||
let Some(matcher) = &self.matcher else {
|
||||
return Verdict::Synced;
|
||||
};
|
||||
let rel = rel.trim_matches('/');
|
||||
if rel.is_empty() {
|
||||
return Verdict::Synced;
|
||||
}
|
||||
let source = |glob: &ignore::gitignore::Glob| match glob.from() {
|
||||
Some(_) => RuleSource::ThisFolder,
|
||||
None => RuleSource::AllFolders,
|
||||
};
|
||||
let mut prefix = String::new();
|
||||
let mut parts = rel.split('/').peekable();
|
||||
while let Some(part) = parts.next() {
|
||||
if !prefix.is_empty() {
|
||||
prefix.push('/');
|
||||
}
|
||||
prefix.push_str(part);
|
||||
let last = parts.peek().is_none();
|
||||
let as_dir = if last { is_dir } else { true };
|
||||
match matcher.matched(&prefix, as_dir) {
|
||||
ignore::Match::Ignore(glob) => {
|
||||
return Verdict::Excluded {
|
||||
pattern: glob.original().to_string(),
|
||||
source: source(glob),
|
||||
};
|
||||
}
|
||||
ignore::Match::Whitelist(glob) if last => {
|
||||
return Verdict::Included {
|
||||
pattern: glob.original().to_string(),
|
||||
source: source(glob),
|
||||
};
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
Verdict::Synced
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for IgnoreRules {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.debug_struct("IgnoreRules")
|
||||
@@ -255,6 +561,198 @@ mod tests {
|
||||
std::fs::write(root.join(name), body).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_added_defaults_leave_out_clutter_but_not_look_alikes() {
|
||||
let dir = TempDir::new();
|
||||
let rules = IgnoreRules::load(dir.path(), &globals());
|
||||
for (clutter, is_dir) in [
|
||||
("desktop.ini", false),
|
||||
("Photos/.directory", false),
|
||||
(".Trash-1000", true),
|
||||
(".Trashes", true),
|
||||
(".Spotlight-V100", true),
|
||||
(".fuse_hidden0000001a00000002", false),
|
||||
(".nfs000000000123abcd", false),
|
||||
("movie.mkv.part", false),
|
||||
("setup.exe.crdownload", false),
|
||||
("notes.txt.kate-swp", false),
|
||||
(".~lock.report.odt#", false),
|
||||
("~$budget.xlsx", false),
|
||||
] {
|
||||
assert!(rules.is_ignored(clutter, is_dir), "{clutter}");
|
||||
}
|
||||
for kept in [
|
||||
"Desktop/notes.txt",
|
||||
"directory.txt",
|
||||
"Trash-talk.md",
|
||||
"nfs-setup.md",
|
||||
"parts.csv",
|
||||
"part.txt",
|
||||
"report.odt",
|
||||
"budget.xlsx",
|
||||
] {
|
||||
assert!(!rules.is_ignored(kept, false), "{kept}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_bad_pattern_is_reported_with_its_line() {
|
||||
assert!(check_pattern("*.db").is_ok());
|
||||
assert!(check_pattern("# a comment").is_ok());
|
||||
assert!(check_pattern("").is_ok());
|
||||
assert!(check_pattern("*.{jpg,png").is_err());
|
||||
assert!(check_pattern("[z-a]").is_err());
|
||||
let bad = check_rules("*.log\n{oops\nbuild/\n");
|
||||
assert_eq!(bad.len(), 1);
|
||||
assert_eq!(bad[0].0, 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn explain_names_the_rule_and_where_it_came_from() {
|
||||
let dir = TempDir::new();
|
||||
write(dir.path(), ".pdfsignore", "*.db\n!keep.tmp\n");
|
||||
let rules = IgnoreRules::load(dir.path(), &globals());
|
||||
assert_eq!(
|
||||
rules.explain("data/cache.db", false),
|
||||
Verdict::Excluded {
|
||||
pattern: "*.db".into(),
|
||||
source: RuleSource::ThisFolder
|
||||
}
|
||||
);
|
||||
assert_eq!(
|
||||
rules.explain("app/node_modules/x/index.js", false),
|
||||
Verdict::Excluded {
|
||||
pattern: "node_modules/".into(),
|
||||
source: RuleSource::AllFolders
|
||||
}
|
||||
);
|
||||
assert_eq!(
|
||||
rules.explain("keep.tmp", false),
|
||||
Verdict::Included {
|
||||
pattern: "!keep.tmp".into(),
|
||||
source: RuleSource::ThisFolder
|
||||
}
|
||||
);
|
||||
assert_eq!(rules.explain("src/main.rs", false), Verdict::Synced);
|
||||
// `explain` and `is_ignored` never disagree.
|
||||
for (path, is_dir) in [
|
||||
("data/cache.db", false),
|
||||
("keep.tmp", false),
|
||||
("x.tmp", false),
|
||||
] {
|
||||
assert_eq!(
|
||||
rules.is_ignored(path, is_dir),
|
||||
matches!(rules.explain(path, is_dir), Verdict::Excluded { .. }),
|
||||
"{path}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rules_being_edited_explain_like_the_saved_ones() {
|
||||
let dir = TempDir::new();
|
||||
let text = "*.db\n!keep.db\n";
|
||||
write(dir.path(), ".pdfsignore", text);
|
||||
let saved = IgnoreRules::load(dir.path(), &globals());
|
||||
let edited = IgnoreRules::with_folder_text(dir.path(), &globals(), text);
|
||||
for path in ["a.db", "keep.db", "node_modules/x", "src/x.rs"] {
|
||||
assert_eq!(
|
||||
saved.explain(path, false),
|
||||
edited.explain(path, false),
|
||||
"{path}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn folder_rules_are_written_back_and_removed_when_blank() {
|
||||
let dir = TempDir::new();
|
||||
let rules = FolderRules::read(dir.path()).unwrap();
|
||||
assert_eq!(rules.text, None);
|
||||
assert_eq!(rules.path, dir.path().join(".pdfsignore"));
|
||||
rules.write("*.db").unwrap();
|
||||
assert_eq!(
|
||||
std::fs::read_to_string(dir.path().join(".pdfsignore")).unwrap(),
|
||||
"*.db\n"
|
||||
);
|
||||
assert!(IgnoreRules::load(dir.path(), &[]).is_ignored("x.db", false));
|
||||
|
||||
let rules = FolderRules::read(dir.path()).unwrap();
|
||||
rules.write(" \n").unwrap();
|
||||
assert!(!dir.path().join(".pdfsignore").exists());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn folder_rules_keep_the_file_name_in_use() {
|
||||
let dir = TempDir::new();
|
||||
write(dir.path(), ".protonignore", "old/\n");
|
||||
let rules = FolderRules::read(dir.path()).unwrap();
|
||||
assert_eq!(rules.path, dir.path().join(".protonignore"));
|
||||
rules.write("new/\n").unwrap();
|
||||
assert!(!dir.path().join(".pdfsignore").exists());
|
||||
assert_eq!(
|
||||
std::fs::read_to_string(dir.path().join(".protonignore")).unwrap(),
|
||||
"new/\n"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn folder_rules_changed_elsewhere_are_not_written_over() {
|
||||
let dir = TempDir::new();
|
||||
write(dir.path(), ".pdfsignore", "a/\n");
|
||||
let rules = FolderRules::read(dir.path()).unwrap();
|
||||
write(dir.path(), ".pdfsignore", "b/\n");
|
||||
assert!(matches!(rules.write("c/"), Err(WriteRulesError::Changed)));
|
||||
assert_eq!(
|
||||
std::fs::read_to_string(dir.path().join(".pdfsignore")).unwrap(),
|
||||
"b/\n"
|
||||
);
|
||||
|
||||
// A file that appeared after an empty read counts as a change too.
|
||||
let dir = TempDir::new();
|
||||
let rules = FolderRules::read(dir.path()).unwrap();
|
||||
write(dir.path(), ".pdfsignore", "b/\n");
|
||||
assert!(matches!(rules.write("c/"), Err(WriteRulesError::Changed)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_pattern_added_to_a_folder_keeps_its_other_lines() {
|
||||
let dir = TempDir::new();
|
||||
assert!(add_folder_pattern(dir.path(), " *.db ").unwrap());
|
||||
assert_eq!(
|
||||
std::fs::read_to_string(dir.path().join(".pdfsignore")).unwrap(),
|
||||
"*.db\n"
|
||||
);
|
||||
|
||||
write(dir.path(), ".pdfsignore", "# my notes\nbuild/");
|
||||
assert!(add_folder_pattern(dir.path(), "*.db").unwrap());
|
||||
assert!(!add_folder_pattern(dir.path(), "build/").unwrap());
|
||||
assert_eq!(
|
||||
std::fs::read_to_string(dir.path().join(".pdfsignore")).unwrap(),
|
||||
"# my notes\nbuild/\n*.db\n"
|
||||
);
|
||||
assert_eq!(
|
||||
FolderRules::read(dir.path()).unwrap().patterns(),
|
||||
["build/", "*.db"]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn removing_a_folder_pattern_keeps_comments_and_drops_an_empty_file() {
|
||||
let dir = TempDir::new();
|
||||
write(dir.path(), ".pdfsignore", "# keep\nbuild/\n*.db\n");
|
||||
assert!(remove_folder_pattern(dir.path(), "build/").unwrap());
|
||||
assert!(!remove_folder_pattern(dir.path(), "build/").unwrap());
|
||||
assert_eq!(
|
||||
std::fs::read_to_string(dir.path().join(".pdfsignore")).unwrap(),
|
||||
"# keep\n*.db\n"
|
||||
);
|
||||
|
||||
write(dir.path(), ".pdfsignore", "*.db\n");
|
||||
assert!(remove_folder_pattern(dir.path(), "*.db").unwrap());
|
||||
assert!(!dir.path().join(".pdfsignore").exists());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn no_rules_at_all_ignores_nothing() {
|
||||
let dir = TempDir::new();
|
||||
|
||||
@@ -14,12 +14,20 @@ pdfs-core.workspace = true
|
||||
zip.workspace = true
|
||||
sha1.workspace = true
|
||||
proton-drive-rs.workspace = true
|
||||
proton-gallery-app-rs.workspace = true
|
||||
proton-gallery-rs.workspace = true
|
||||
hyper = { version = "1", features = ["http1", "server"] }
|
||||
hyper-util = { version = "0.1", features = ["tokio"] }
|
||||
http-body-util = "0.1"
|
||||
getrandom = "0.4"
|
||||
zeroize.workspace = true
|
||||
futures.workspace = true
|
||||
async-trait.workspace = true
|
||||
tokio.workspace = true
|
||||
tracing.workspace = true
|
||||
fuser.workspace = true
|
||||
libc.workspace = true
|
||||
rustix = { version = "1", features = ["net", "process"] }
|
||||
serde.workspace = true
|
||||
serde_json.workspace = true
|
||||
base64.workspace = true
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
//! than looked up in our own timeline, where a shared album's photos never
|
||||
//! appear.
|
||||
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::collections::HashSet;
|
||||
use std::sync::atomic::Ordering;
|
||||
|
||||
use pdfs_core::control::{AlbumInfo, PhotoItem, Topic};
|
||||
@@ -24,8 +24,8 @@ use proton_drive_rs::proton_sdk::ids::NodeUid;
|
||||
use tracing::warn;
|
||||
|
||||
use super::{
|
||||
ALBUM_SYNCED_PREFIX, ALBUMS_SYNCED_MS, Core, PHOTOS_AVAILABLE, PHOTOS_SYNCED_MS,
|
||||
TIMELINE_ENRICH_CHUNK, TIMELINE_TTL, now_ms, parse_uid,
|
||||
ALBUM_SYNCED_PREFIX, ALBUMS_SYNCED_MS, Core, PHOTOS_AVAILABLE, TIMELINE_ENRICH_CHUNK,
|
||||
TIMELINE_TTL, link, now_ms, parse_uid,
|
||||
};
|
||||
|
||||
impl Core {
|
||||
@@ -34,7 +34,13 @@ impl Core {
|
||||
/// [`Core::photos_timeline`] gives.
|
||||
pub(crate) fn albums(&self) -> CoreResult<Option<Vec<AlbumInfo>>> {
|
||||
let count = self.db.albums_count().map_err(CoreError::from)?;
|
||||
if count == 0 {
|
||||
if count == 0
|
||||
&& self
|
||||
.db
|
||||
.state_i64(ALBUMS_SYNCED_MS)
|
||||
.map_err(CoreError::from)?
|
||||
.is_none()
|
||||
{
|
||||
// Nothing on disk, so this one request waits for the fetch — unless
|
||||
// the account is already known to have no photos volume.
|
||||
let known_empty = self.db.state_i64(PHOTOS_AVAILABLE).ok().flatten() == Some(0);
|
||||
@@ -56,77 +62,71 @@ impl Core {
|
||||
/// the persisted listing. Returns false when the account has no photos
|
||||
/// volume.
|
||||
pub(crate) async fn refresh_albums(&self) -> CoreResult<bool> {
|
||||
let generation = self
|
||||
.db
|
||||
.photo_projection_generation()
|
||||
.map_err(CoreError::from)?;
|
||||
let photos = self.photos();
|
||||
if photos
|
||||
.get_photos_root()
|
||||
if link::bounded(photos.get_photos_root())
|
||||
.await
|
||||
.map_err(|e| CoreError::from_api(&e, "photos root"))?
|
||||
.is_none()
|
||||
{
|
||||
let _ = self.db.set_state_i64(PHOTOS_AVAILABLE, 0);
|
||||
let _ = self.db.set_state_i64(PHOTOS_SYNCED_MS, now_ms());
|
||||
let _ = self.db.set_state_i64(ALBUMS_SYNCED_MS, now_ms());
|
||||
self.db
|
||||
.albums_replace_at(&[], generation, now_ms())
|
||||
.map_err(CoreError::from)?;
|
||||
return Ok(false);
|
||||
}
|
||||
|
||||
let mut uids = photos
|
||||
.enumerate_album_node_uids()
|
||||
let mut uids = link::bounded(photos.enumerate_album_node_uids())
|
||||
.await
|
||||
.map_err(|e| CoreError::from_api(&e, "albums"))?;
|
||||
let shared = link::bounded(photos.enumerate_shared_with_me_album_uids())
|
||||
.await
|
||||
.map_err(|e| CoreError::from_api(&e, "shared albums"))?;
|
||||
let shared_keys: HashSet<_> = shared.iter().map(ToString::to_string).collect();
|
||||
uids.extend(shared);
|
||||
let mut unique = HashSet::new();
|
||||
uids.retain(|uid| unique.insert(uid.clone()));
|
||||
|
||||
// Shared-with-me albums are a separate listing on the sharer's volume.
|
||||
// Best-effort: an account whose sharing listing fails still gets its own
|
||||
// albums rather than an error page.
|
||||
let shared: HashSet<String> = match photos.enumerate_shared_with_me_album_uids().await {
|
||||
Ok(shared) => {
|
||||
let keys = shared.iter().map(|u| u.to_string()).collect();
|
||||
uids.extend(shared);
|
||||
keys
|
||||
}
|
||||
Err(e) => {
|
||||
warn!(error = %e, "enumerating shared-with-me albums failed");
|
||||
HashSet::new()
|
||||
}
|
||||
};
|
||||
|
||||
// The listings carry uids only; the name, photo count and cover come from
|
||||
// the album nodes themselves. A chunk that fails to resolve drops those
|
||||
// albums from this refresh rather than failing the whole listing.
|
||||
let mut albums: Vec<StoredAlbum> = Vec::with_capacity(uids.len());
|
||||
let mut albums = Vec::with_capacity(uids.len());
|
||||
for chunk in uids.chunks(TIMELINE_ENRICH_CHUNK) {
|
||||
match photos.enumerate_nodes(chunk).await {
|
||||
Ok(nodes) => {
|
||||
for node in nodes {
|
||||
let key = node.uid.to_string();
|
||||
let props = node.album.as_ref();
|
||||
albums.push(StoredAlbum {
|
||||
shared: shared.contains(&key),
|
||||
uid: key,
|
||||
name: node.name,
|
||||
photo_count: props.map_or(0, |a| a.photo_count.max(0) as usize),
|
||||
cover_uid: props
|
||||
.and_then(|a| a.cover_photo_uid.as_ref())
|
||||
.map(|u| u.to_string()),
|
||||
last_activity: props.and_then(|a| a.last_activity_time),
|
||||
});
|
||||
}
|
||||
}
|
||||
Err(e) => warn!(error = %e, "resolving an album chunk failed"),
|
||||
let nodes = link::bounded(photos.enumerate_nodes(chunk))
|
||||
.await
|
||||
.map_err(|e| CoreError::from_api(&e, "album metadata"))?;
|
||||
if nodes.len() != chunk.len() {
|
||||
return Err(CoreError::remote(
|
||||
"Some album details are still unavailable.",
|
||||
));
|
||||
}
|
||||
for node in nodes.into_iter().filter(|node| !node.trashed) {
|
||||
let uid = node.uid.to_string();
|
||||
let props = node.album.as_ref();
|
||||
albums.push(StoredAlbum {
|
||||
shared: shared_keys.contains(&uid),
|
||||
uid,
|
||||
name: node.name,
|
||||
photo_count: props.map_or(0, |a| a.photo_count.max(0) as usize),
|
||||
cover_uid: props
|
||||
.and_then(|a| a.cover_photo_uid.as_ref())
|
||||
.map(ToString::to_string),
|
||||
last_activity: props.and_then(|a| a.last_activity_time),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Newest activity first, and albums the server gave no activity time for
|
||||
// last — an album nobody has touched belongs below the ones in use. Ties
|
||||
// fall back to the name so the order is stable between refreshes.
|
||||
albums.sort_by(|a, b| {
|
||||
b.last_activity
|
||||
.cmp(&a.last_activity)
|
||||
.then_with(|| a.name.to_lowercase().cmp(&b.name.to_lowercase()))
|
||||
});
|
||||
|
||||
self.db.albums_replace(&albums).map_err(CoreError::from)?;
|
||||
let _ = self.db.set_state_i64(PHOTOS_AVAILABLE, 1);
|
||||
let _ = self.db.set_state_i64(ALBUMS_SYNCED_MS, now_ms());
|
||||
if !self
|
||||
.db
|
||||
.albums_replace_at(&albums, generation, now_ms())
|
||||
.map_err(CoreError::from)?
|
||||
{
|
||||
return Err(CoreError::remote(
|
||||
"Photos changed during the album refresh. Try again shortly.",
|
||||
));
|
||||
}
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
@@ -154,11 +154,21 @@ impl Core {
|
||||
album: &NodeUid,
|
||||
offset: usize,
|
||||
limit: usize,
|
||||
excluded: &str,
|
||||
) -> CoreResult<Vec<PhotoItem>> {
|
||||
let key = album.to_string();
|
||||
if self.db.photo_removed(&key).map_err(CoreError::from)? {
|
||||
return Ok(Vec::new());
|
||||
}
|
||||
let stamp = format!("{ALBUM_SYNCED_PREFIX}{key}");
|
||||
let count = self.db.album_photos_count(&key).map_err(CoreError::from)?;
|
||||
if count == 0 {
|
||||
if count == 0
|
||||
&& self
|
||||
.db
|
||||
.state_i64(&stamp)
|
||||
.map_err(CoreError::from)?
|
||||
.is_none()
|
||||
{
|
||||
self.rt.block_on(self.refresh_album(album))?;
|
||||
} else if self.listing_stale(&stamp, TIMELINE_TTL) {
|
||||
let core = self.clone();
|
||||
@@ -172,7 +182,7 @@ impl Core {
|
||||
|
||||
let page = self
|
||||
.db
|
||||
.album_photos_page(&key, offset, limit)
|
||||
.album_photos_page_visible(&key, offset, limit, excluded)
|
||||
.map_err(CoreError::from)?;
|
||||
Ok(page.into_iter().map(|p| self.photo_item(p)).collect())
|
||||
}
|
||||
@@ -213,47 +223,56 @@ impl Core {
|
||||
|
||||
/// Re-enumerate one album's photos and replace its persisted contents.
|
||||
pub(crate) async fn refresh_album(&self, album: &NodeUid) -> CoreResult<()> {
|
||||
let generation = self
|
||||
.db
|
||||
.photo_projection_generation()
|
||||
.map_err(CoreError::from)?;
|
||||
let photos = self.photos();
|
||||
let items = photos
|
||||
.enumerate_album(album)
|
||||
let items = link::bounded(photos.enumerate_album(album))
|
||||
.await
|
||||
.map_err(|e| CoreError::from_api(&e, "album"))?;
|
||||
|
||||
// Same enrichment as the timeline: the listing carries a uid and a
|
||||
// capture time, and the gallery needs a name and media type to classify
|
||||
// each entry. Best-effort per chunk.
|
||||
let uids: Vec<NodeUid> = items.iter().map(|it| it.uid.clone()).collect();
|
||||
let mut meta: HashMap<String, (Option<String>, Option<String>)> = HashMap::new();
|
||||
let key = album.to_string();
|
||||
let mut meta = self
|
||||
.db
|
||||
.album_photo_metadata(&key)
|
||||
.map_err(CoreError::from)?;
|
||||
let uids: Vec<NodeUid> = items
|
||||
.iter()
|
||||
.filter(|item| !meta.contains_key(&item.uid.to_string()))
|
||||
.map(|item| item.uid.clone())
|
||||
.collect();
|
||||
for chunk in uids.chunks(TIMELINE_ENRICH_CHUNK) {
|
||||
match photos.enumerate_nodes(chunk).await {
|
||||
Ok(nodes) => {
|
||||
for node in nodes {
|
||||
let media_type = match &node.kind {
|
||||
NodeKind::File { media_type, .. } => Some(media_type.clone()),
|
||||
NodeKind::Folder => None,
|
||||
};
|
||||
meta.insert(node.uid.to_string(), (Some(node.name), media_type));
|
||||
}
|
||||
}
|
||||
Err(e) => warn!(error = %e, "resolving album photo metadata failed"),
|
||||
let nodes = link::bounded(photos.enumerate_nodes(chunk))
|
||||
.await
|
||||
.map_err(|e| CoreError::from_api(&e, "album photo metadata"))?;
|
||||
for node in nodes.into_iter().filter(|node| !node.trashed) {
|
||||
let media_type = match node.kind {
|
||||
NodeKind::File { media_type, .. } => Some(media_type),
|
||||
NodeKind::Folder => None,
|
||||
};
|
||||
meta.insert(node.uid.to_string(), (node.name, media_type));
|
||||
}
|
||||
}
|
||||
|
||||
let rows: Vec<(String, i64, Option<String>, Option<String>)> = items
|
||||
.iter()
|
||||
.map(|it| {
|
||||
let key = it.uid.to_string();
|
||||
let (name, media_type) = meta.get(&key).cloned().unwrap_or((None, None));
|
||||
(key, it.capture_time, name, media_type)
|
||||
let rows: Vec<_> = items
|
||||
.into_iter()
|
||||
.map(|item| {
|
||||
let uid = item.uid.to_string();
|
||||
let (name, media_type) = meta
|
||||
.get(&uid)
|
||||
.map(|(name, mime)| (Some(name.clone()), mime.clone()))
|
||||
.unwrap_or_default();
|
||||
(uid, item.capture_time, name, media_type)
|
||||
})
|
||||
.collect();
|
||||
let key = album.to_string();
|
||||
self.db
|
||||
.album_photos_replace(&key, &rows)
|
||||
.map_err(CoreError::from)?;
|
||||
let _ = self
|
||||
if !self
|
||||
.db
|
||||
.set_state_i64(&format!("{ALBUM_SYNCED_PREFIX}{key}"), now_ms());
|
||||
.album_photos_replace_at(&key, &rows, generation, now_ms())
|
||||
.map_err(CoreError::from)?
|
||||
{
|
||||
return Err(CoreError::remote(
|
||||
"Photos changed during the album refresh. Try again shortly.",
|
||||
));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -283,7 +302,7 @@ impl Core {
|
||||
.block_on(self.photos().delete_album(album, delete_photos))
|
||||
.map_err(|e| CoreError::from_api(&e, "delete album"))?;
|
||||
let key = album.to_string();
|
||||
if let Err(error) = self.db.album_photos_replace(&key, &[]) {
|
||||
if let Err(error) = self.db.photos_delete(&[key]) {
|
||||
warn!(%album, %error, "a deleted album's photos could not be dropped");
|
||||
}
|
||||
self.after_album_change(None);
|
||||
|
||||
@@ -517,32 +517,15 @@ pub(super) async fn run_event_sync(
|
||||
}
|
||||
}
|
||||
|
||||
/// The state key holding the photos volume's event cursor. Separate from the
|
||||
/// Drive cursor because the two volumes have their own event streams, and one
|
||||
/// cursor cannot address both.
|
||||
const PHOTOS_EVENT_CURSOR: &str = "photos_event_cursor";
|
||||
|
||||
/// Poll the photos volume's event stream, so a photo deleted or added on another
|
||||
/// device shows up in the gallery within one poll instead of on the timeline's
|
||||
/// freshness window.
|
||||
///
|
||||
/// Deliberately much smaller than [`run_event_sync`]: the photos volume is not
|
||||
/// part of the FUSE mount, so there is no inode space to converge and nothing to
|
||||
/// invalidate in the kernel. A trash or a delete removes the rows behind the
|
||||
/// gallery; anything else only drops the timeline's freshness stamp, and the
|
||||
/// next read re-enumerates. Getting that wrong costs a stale tile, not a wrong
|
||||
/// file.
|
||||
/// Follow the Photos volume and commit changes with its durable event cursor.
|
||||
pub(super) async fn run_photos_event_sync(core: Core) {
|
||||
let photos = core.photos();
|
||||
// The photos volume only exists once the user has used Photos at all, and
|
||||
// the daemon may well start before the network does.
|
||||
let scope = loop {
|
||||
match photos.get_photos_root().await {
|
||||
match link::bounded(photos.get_photos_root()).await {
|
||||
Ok(Some(root)) => break root.tree_event_scope_id(),
|
||||
Ok(None) => {
|
||||
debug!("no photos volume; photo event sync not started");
|
||||
return;
|
||||
}
|
||||
Ok(None) => core.next_poll(POLL_INTERVAL).await,
|
||||
Err(error) if session_revoked(&error) => {
|
||||
core.mark_session_expired("read the photos root", &error);
|
||||
return;
|
||||
@@ -554,39 +537,71 @@ pub(super) async fn run_photos_event_sync(core: Core) {
|
||||
}
|
||||
};
|
||||
|
||||
let mut cursor: Option<DriveEventId> = core
|
||||
.db
|
||||
.state_str(PHOTOS_EVENT_CURSOR)
|
||||
.ok()
|
||||
.flatten()
|
||||
.map(DriveEventId::from);
|
||||
info!(?cursor, "photo event sync started");
|
||||
let key = format!("photos_event_cursor:{}", scope.volume_id());
|
||||
let mut cursor = loop {
|
||||
match core.db.state_str(&key) {
|
||||
Ok(cursor) => break cursor.map(DriveEventId::from),
|
||||
Err(error) => {
|
||||
warn!(%error, "reading the photo event checkpoint failed");
|
||||
core.next_poll(POLL_INTERVAL).await;
|
||||
}
|
||||
}
|
||||
};
|
||||
info!("photo event sync started");
|
||||
|
||||
loop {
|
||||
core.next_poll(POLL_INTERVAL).await;
|
||||
let events = match link::bounded(photos.enumerate_events(&scope, cursor.as_ref())).await {
|
||||
Ok(events) => events,
|
||||
Err(error) if core.lost_link(&error, "poll photo events") => continue,
|
||||
Err(error) => {
|
||||
warn!(%error, "photo event poll failed; retrying after interval");
|
||||
if !core.lost_link(&error, "poll photo events") {
|
||||
warn!(%error, "photo event poll failed; retrying after interval");
|
||||
}
|
||||
core.next_poll(POLL_INTERVAL).await;
|
||||
continue;
|
||||
}
|
||||
};
|
||||
let Some(head) = events.last().map(|event| event.id().clone()) else {
|
||||
continue;
|
||||
};
|
||||
apply_photo_events(&core, &events);
|
||||
core.events.publish(&[Topic::Photos]);
|
||||
// One cursor write per batch, after the batch is applied: a crash in
|
||||
// between replays events whose effects are idempotent.
|
||||
if let Err(error) = core.db.set_state_str(PHOTOS_EVENT_CURSOR, head.as_str()) {
|
||||
warn!(%error, "persisting the photo event cursor failed");
|
||||
continue;
|
||||
if let Some(head) = events.last().map(|event| event.id().clone()) {
|
||||
if let Err(error) = invalidate_photo_events(&core, &events).await {
|
||||
warn!(%error, "invalidating photo event metadata failed");
|
||||
core.next_poll(POLL_INTERVAL).await;
|
||||
continue;
|
||||
}
|
||||
// A failed database write must replay all changes, including echoes.
|
||||
let plan = classify_photo_events(&events, |_| false);
|
||||
if let Err(error) = core.db.photos_apply_events(
|
||||
&key,
|
||||
head.as_str(),
|
||||
&plan.gone,
|
||||
&plan.touched,
|
||||
plan.full,
|
||||
cursor.is_none(),
|
||||
) {
|
||||
warn!(%error, "committing the photo event checkpoint failed");
|
||||
core.next_poll(POLL_INTERVAL).await;
|
||||
continue;
|
||||
}
|
||||
cursor = Some(head);
|
||||
if !plan.is_empty() {
|
||||
core.events.publish(&[Topic::Photos]);
|
||||
}
|
||||
}
|
||||
cursor = Some(head);
|
||||
if core.db.photos_need_work().unwrap_or(true) {
|
||||
core.spawn_timeline_refresh();
|
||||
}
|
||||
core.next_poll(POLL_INTERVAL).await;
|
||||
}
|
||||
}
|
||||
|
||||
async fn invalidate_photo_events(
|
||||
core: &Core,
|
||||
events: &[DriveEvent],
|
||||
) -> proton_drive_rs::proton_sdk::error::Result<()> {
|
||||
for event in events {
|
||||
core.client.invalidate_caches_for_event(event).await?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// What one batch of photos-volume events asks the gallery's tables to do.
|
||||
#[derive(Debug, Default, PartialEq)]
|
||||
pub(super) struct PhotoEventPlan {
|
||||
@@ -616,14 +631,22 @@ fn classify_photo_events(
|
||||
mut is_echo: impl FnMut(&NodeUid) -> bool,
|
||||
) -> PhotoEventPlan {
|
||||
let mut plan = PhotoEventPlan::default();
|
||||
for event in events {
|
||||
let mut seen = HashSet::new();
|
||||
for event in events.iter().rev() {
|
||||
match event {
|
||||
DriveEvent::NodeDeleted { node_uid, .. } => plan.gone.push(node_uid.to_string()),
|
||||
DriveEvent::NodeDeleted { node_uid, .. } => {
|
||||
if seen.insert(node_uid) {
|
||||
plan.gone.push(node_uid.to_string());
|
||||
}
|
||||
}
|
||||
DriveEvent::NodeUpdated {
|
||||
node_uid,
|
||||
is_trashed,
|
||||
..
|
||||
} => {
|
||||
if !seen.insert(node_uid) {
|
||||
continue;
|
||||
}
|
||||
if *is_trashed {
|
||||
plan.gone.push(node_uid.to_string());
|
||||
} else if !is_echo(node_uid) {
|
||||
@@ -641,47 +664,11 @@ fn classify_photo_events(
|
||||
DriveEvent::CursorAdvanced { .. } | DriveEvent::SharedWithMeUpdated { .. } => {}
|
||||
}
|
||||
}
|
||||
plan.gone.reverse();
|
||||
plan.touched.reverse();
|
||||
plan
|
||||
}
|
||||
|
||||
/// Apply one batch of photos-volume events to the gallery's tables.
|
||||
fn apply_photo_events(core: &Core, events: &[DriveEvent]) {
|
||||
let plan = classify_photo_events(events, |uid| core.take_self_change(uid));
|
||||
let PhotoEventPlan {
|
||||
gone,
|
||||
touched,
|
||||
full,
|
||||
} = &plan;
|
||||
if !gone.is_empty() {
|
||||
match core.db.photos_delete(gone) {
|
||||
Ok(removed) if removed > 0 => {
|
||||
debug!(removed, "photos removed by a remote event");
|
||||
}
|
||||
Ok(_) => {}
|
||||
Err(error) => warn!(%error, "removing remotely deleted photos failed"),
|
||||
}
|
||||
}
|
||||
// A stale mark is what makes the next refresh cheap: it reads these photos'
|
||||
// nodes and carries every other photo's metadata as it stands.
|
||||
if !touched.is_empty() {
|
||||
match core.db.photos_mark_unresolved(touched) {
|
||||
Ok(marked) if marked > 0 => debug!(marked, "photos changed by a remote event"),
|
||||
Ok(_) => {}
|
||||
Err(error) => warn!(%error, "marking remotely changed photos failed"),
|
||||
}
|
||||
}
|
||||
if *full {
|
||||
match core.db.photos_mark_all_unresolved() {
|
||||
Ok(marked) => debug!(marked, "the photo event stream lost continuity"),
|
||||
Err(error) => warn!(%error, "marking the whole timeline unresolved failed"),
|
||||
}
|
||||
}
|
||||
if !plan.is_empty() {
|
||||
core.invalidate_photos();
|
||||
core.invalidate_albums();
|
||||
}
|
||||
}
|
||||
|
||||
/// Keep the local-file index fresh for the launcher prompt's "This computer"
|
||||
/// results. Rebuilds the index whenever it is older than [`LOCAL_INDEX_TTL`],
|
||||
/// then sleeps; runs on its own thread for the life of the daemon.
|
||||
|
||||
@@ -396,6 +396,11 @@ fn touched_topics(request: &CtlRequest) -> &'static [Topic] {
|
||||
use CtlRequest as R;
|
||||
match request {
|
||||
R::Pin { .. } | R::Unpin { .. } => &[Topic::Files],
|
||||
// Only locking invalidates a hidden view. Authentication does not
|
||||
// change the public catalog and must not emit this notification.
|
||||
R::DriveGallery {
|
||||
action: pdfs_core::control::GalleryAction::Lock,
|
||||
} => &[Topic::GalleryVisibility],
|
||||
R::CreateAlbum { .. }
|
||||
| R::RenameAlbum { .. }
|
||||
| R::DeleteAlbum { .. }
|
||||
@@ -552,6 +557,68 @@ fn handle_control_conn(core: &Core, username: &str, mountpoint: &Path, stream: U
|
||||
// Registered before the request is even parsed, so a handler that wedges
|
||||
// inside the daemon shows up by name in `pdfs diagnostics`.
|
||||
let _inflight = super::diagnostics::InflightGuard::new(super::diagnostics::request_kind(&line));
|
||||
if let Ok(CtlRequest::PhotoMonths { kind }) = &request {
|
||||
let started = std::time::Instant::now();
|
||||
let visibility = core.cached_gallery_visibility();
|
||||
let visibility_ms = started.elapsed().as_millis() as u64;
|
||||
let mut database_ms = None;
|
||||
let mut response_started = std::time::Instant::now();
|
||||
let response = match visibility {
|
||||
Ok(visibility) => {
|
||||
let excluded = serde_json::to_string(&visibility.media)
|
||||
.expect("a set of file identifiers serializes");
|
||||
let query = std::time::Instant::now();
|
||||
let months = core.db.photos_months_visible(*kind, &excluded);
|
||||
response_started = std::time::Instant::now();
|
||||
database_ms = Some(response_started.duration_since(query).as_millis() as u64);
|
||||
match months {
|
||||
Ok(months) => CtlResponse::PhotoMonths {
|
||||
months: months
|
||||
.into_iter()
|
||||
.map(|(year, month, count)| PhotoMonth { year, month, count })
|
||||
.collect(),
|
||||
},
|
||||
Err(error) => CtlResponse::error(error.into()),
|
||||
}
|
||||
}
|
||||
Err(error) => CtlResponse::error(error),
|
||||
};
|
||||
write_response(stream, response);
|
||||
tracing::info!(
|
||||
visibility_ms,
|
||||
database_ms,
|
||||
response_ms = response_started.elapsed().as_millis() as u64,
|
||||
total_ms = started.elapsed().as_millis() as u64,
|
||||
"PhotoMonths timings"
|
||||
);
|
||||
return;
|
||||
}
|
||||
let visibility = if matches!(
|
||||
&request,
|
||||
Ok(CtlRequest::PhotosTimeline { .. }
|
||||
| CtlRequest::PhotoDuplicates
|
||||
| CtlRequest::PhotoSimilar
|
||||
| CtlRequest::PhotoPlaces
|
||||
| CtlRequest::PlacePhotos { .. }
|
||||
| CtlRequest::PlaceLocations { .. }
|
||||
| CtlRequest::PhotosOnThisDay { .. }
|
||||
| CtlRequest::PhotoGroup { .. }
|
||||
| CtlRequest::PhotoAlbums
|
||||
| CtlRequest::AlbumPhotos { .. }
|
||||
| CtlRequest::PhotoThumbs { .. }
|
||||
| CtlRequest::OpenGalleryImage { private: false, .. }
|
||||
| CtlRequest::OpenPhoto { .. })
|
||||
) {
|
||||
core.gallery_visibility()
|
||||
} else {
|
||||
Ok(std::sync::Arc::default())
|
||||
};
|
||||
let visibility = match visibility {
|
||||
Ok(visibility) => visibility,
|
||||
Err(error) => return write_response(stream, CtlResponse::error(error)),
|
||||
};
|
||||
let excluded =
|
||||
serde_json::to_string(&visibility.media).expect("a set of file identifiers serializes");
|
||||
let response = match request {
|
||||
Ok(CtlRequest::Status) => status_response(core, username, mountpoint),
|
||||
Ok(CtlRequest::Subscribe) => {
|
||||
@@ -627,7 +694,7 @@ fn handle_control_conn(core: &Core, username: &str, mountpoint: &Path, stream: U
|
||||
// A full refresh is "forget what you know", not a second code
|
||||
// path: the ordinary refresh then finds every photo stale.
|
||||
if let Some(Err(e)) = full.then(|| core.db.photos_mark_all_unresolved()) {
|
||||
warn!(error = %e, "marking the whole timeline unresolved failed");
|
||||
return write_response(stream, CtlResponse::error(e.into()));
|
||||
}
|
||||
// Whatever changed the timeline can just as easily have
|
||||
// changed an album; one scope covers the whole photos view.
|
||||
@@ -668,11 +735,12 @@ fn handle_control_conn(core: &Core, username: &str, mountpoint: &Path, stream: U
|
||||
range,
|
||||
favorites,
|
||||
not_in_album,
|
||||
&excluded,
|
||||
) {
|
||||
Ok(Some(items)) => CtlResponse::Photos {
|
||||
available: true,
|
||||
items,
|
||||
counts: core.db.photos_counts().ok(),
|
||||
counts: core.db.photos_counts_visible(&excluded).ok(),
|
||||
},
|
||||
Ok(None) => CtlResponse::Photos {
|
||||
available: false,
|
||||
@@ -693,7 +761,7 @@ fn handle_control_conn(core: &Core, username: &str, mountpoint: &Path, stream: U
|
||||
},
|
||||
Err(e) => CtlResponse::error(e),
|
||||
},
|
||||
Ok(CtlRequest::PhotoPlaces) => match core.photo_places() {
|
||||
Ok(CtlRequest::PhotoPlaces) => match core.photo_places(&excluded) {
|
||||
Ok(items) => CtlResponse::Places {
|
||||
items,
|
||||
mapping: core.timeline_progress(),
|
||||
@@ -701,7 +769,7 @@ fn handle_control_conn(core: &Core, username: &str, mountpoint: &Path, stream: U
|
||||
Err(e) => CtlResponse::error(e),
|
||||
},
|
||||
Ok(CtlRequest::PlacePhotos { id, offset, limit }) => {
|
||||
match core.place_photos(id, offset, clamp_limit(limit)) {
|
||||
match core.place_photos(id, offset, clamp_limit(limit), &excluded) {
|
||||
Ok(items) => CtlResponse::Photos {
|
||||
available: true,
|
||||
items,
|
||||
@@ -715,7 +783,7 @@ fn handle_control_conn(core: &Core, username: &str, mountpoint: &Path, stream: U
|
||||
Err(e) => CtlResponse::error(e),
|
||||
},
|
||||
Ok(CtlRequest::PhotosOnThisDay { limit }) => {
|
||||
match core.photos_on_this_day(clamp_limit(limit)) {
|
||||
match core.photos_on_this_day(clamp_limit(limit), &excluded) {
|
||||
Ok(items) => CtlResponse::Photos {
|
||||
available: true,
|
||||
items,
|
||||
@@ -760,7 +828,10 @@ fn handle_control_conn(core: &Core, username: &str, mountpoint: &Path, stream: U
|
||||
// An album page is a timeline page as far as the front-end is
|
||||
// concerned, so it comes back in the same reply — with `counts`
|
||||
// unset, which describe the whole timeline rather than this album.
|
||||
Some(album) => match core.album_photos(&album, offset, clamp_limit(limit)) {
|
||||
Some(album) => match visibility
|
||||
.permits(&uid)
|
||||
.and_then(|()| core.album_photos(&album, offset, clamp_limit(limit), &excluded))
|
||||
{
|
||||
Ok(items) => CtlResponse::Photos {
|
||||
available: true,
|
||||
items,
|
||||
@@ -802,17 +873,28 @@ fn handle_control_conn(core: &Core, username: &str, mountpoint: &Path, stream: U
|
||||
core.remove_from_album(album, photos)
|
||||
})
|
||||
}
|
||||
Ok(CtlRequest::PhotoMonths { kind }) => match core.db.photos_months(kind) {
|
||||
Ok(months) => CtlResponse::PhotoMonths {
|
||||
months: months
|
||||
.into_iter()
|
||||
.map(|(year, month, count)| PhotoMonth { year, month, count })
|
||||
.collect(),
|
||||
Ok(CtlRequest::PhotoPresence { uid, album }) => match core.cached_gallery_visibility() {
|
||||
Ok(visibility)
|
||||
if visibility.media.contains(&uid)
|
||||
|| album
|
||||
.as_ref()
|
||||
.is_some_and(|uid| visibility.albums.contains(uid)) =>
|
||||
{
|
||||
CtlResponse::PhotoPresence { present: false }
|
||||
}
|
||||
Ok(_) => match core.db.photos_contains(&uid, album.as_deref()) {
|
||||
Ok(present) => CtlResponse::PhotoPresence { present },
|
||||
Err(error) => CtlResponse::error(error.into()),
|
||||
},
|
||||
Err(e) => CtlResponse::error(e.into()),
|
||||
Err(error) => CtlResponse::error(error),
|
||||
},
|
||||
Ok(CtlRequest::PhotoMonths { .. }) => unreachable!("handled before visibility requests"),
|
||||
Ok(CtlRequest::PhotoThumbs { uids }) => {
|
||||
let parsed: Vec<NodeUid> = uids.iter().filter_map(|u| parse_uid(u)).collect();
|
||||
let parsed: Vec<NodeUid> = uids
|
||||
.iter()
|
||||
.filter(|uid| !visibility.media.contains(*uid))
|
||||
.filter_map(|u| parse_uid(u))
|
||||
.collect();
|
||||
CtlResponse::Thumbs {
|
||||
items: core.photo_thumbs(&parsed),
|
||||
}
|
||||
@@ -862,7 +944,7 @@ fn handle_control_conn(core: &Core, username: &str, mountpoint: &Path, stream: U
|
||||
running: core.timeline_refreshing(),
|
||||
},
|
||||
Ok(CtlRequest::OpenPhoto { uid }) => match parse_uid(&uid) {
|
||||
Some(u) => match core.open_photo(&u) {
|
||||
Some(u) => match visibility.permits(&uid).and_then(|()| core.open_photo(&u)) {
|
||||
Ok(p) => CtlResponse::FilePath {
|
||||
path: p.display().to_string(),
|
||||
},
|
||||
@@ -870,6 +952,38 @@ fn handle_control_conn(core: &Core, username: &str, mountpoint: &Path, stream: U
|
||||
},
|
||||
None => CtlResponse::error(CoreError::invalid(format!("bad uid: {uid}"))),
|
||||
},
|
||||
Ok(CtlRequest::DriveGallery {
|
||||
action: pdfs_core::control::GalleryAction::AuthenticateHidden,
|
||||
}) => core
|
||||
.authenticate_hidden_gallery(&stream)
|
||||
.unwrap_or_else(CtlResponse::error),
|
||||
Ok(CtlRequest::DriveGallery { action }) => core
|
||||
.drive_gallery(action)
|
||||
.unwrap_or_else(CtlResponse::error),
|
||||
Ok(CtlRequest::OpenGalleryVideo { uid, private }) => core
|
||||
.open_gallery_video(&uid, private)
|
||||
.unwrap_or_else(CtlResponse::error),
|
||||
Ok(CtlRequest::OpenGalleryImage { uid, private: true }) => {
|
||||
core.gallery_image(&uid).unwrap_or_else(CtlResponse::error)
|
||||
}
|
||||
Ok(CtlRequest::OpenGalleryImage {
|
||||
uid,
|
||||
private: false,
|
||||
}) => match visibility
|
||||
.permits(&uid)
|
||||
.and_then(|()| core.open_shared_file(&uid))
|
||||
{
|
||||
Ok(path) => CtlResponse::FilePath {
|
||||
path: path.display().to_string(),
|
||||
},
|
||||
Err(error) => CtlResponse::error(error),
|
||||
},
|
||||
Ok(CtlRequest::CloseGalleryVideo { token }) => core
|
||||
.close_gallery_video(&token)
|
||||
.unwrap_or_else(CtlResponse::error),
|
||||
Ok(CtlRequest::GalleryThumbnail { uid, private }) => core
|
||||
.gallery_thumbnail(&uid, private)
|
||||
.unwrap_or_else(CtlResponse::error),
|
||||
// The scan alone walks every archive's central directory, so even the
|
||||
// dry run goes to a background thread and is read back through
|
||||
// `ImportStatus` rather than answered inline.
|
||||
@@ -986,7 +1100,8 @@ fn handle_control_conn(core: &Core, username: &str, mountpoint: &Path, stream: U
|
||||
// timeline, and the GUI reloads the gallery the moment this
|
||||
// reply lands — so refresh now rather than leaving it to a
|
||||
// background pass that would land just after that reload.
|
||||
if let Err(e) = core.rt.block_on(core.refresh_timeline()) {
|
||||
core.invalidate_photos();
|
||||
if let Err(e) = core.refresh_timeline_joined() {
|
||||
warn!(error = %e, "timeline refresh after upload failed");
|
||||
}
|
||||
CtlResponse::Ok {
|
||||
@@ -1320,11 +1435,9 @@ fn handle_control_conn(core: &Core, username: &str, mountpoint: &Path, stream: U
|
||||
core.cache.set_budget(bytes);
|
||||
// Persist so the next mount keeps the new cap. Best-effort: a config
|
||||
// write failure is reported but the live cap is already applied.
|
||||
match AppDirs::new().map(|dirs| {
|
||||
let mut cfg = dirs.load_config();
|
||||
cfg.cache_budget = Some(bytes);
|
||||
dirs.save_config(&cfg)
|
||||
}) {
|
||||
match AppDirs::new()
|
||||
.map(|dirs| dirs.update_config(|cfg| cfg.cache_budget = Some(bytes)))
|
||||
{
|
||||
Ok(Ok(())) => {
|
||||
core.touch_profile();
|
||||
CtlResponse::Ok {
|
||||
@@ -1344,10 +1457,10 @@ fn handle_control_conn(core: &Core, username: &str, mountpoint: &Path, stream: U
|
||||
// Persisted like the cache budget: best-effort, the live caps are
|
||||
// already applied.
|
||||
match AppDirs::new().map(|dirs| {
|
||||
let mut cfg = dirs.load_config();
|
||||
cfg.upload_limit = Some(upload);
|
||||
cfg.download_limit = Some(download);
|
||||
dirs.save_config(&cfg)
|
||||
dirs.update_config(|cfg| {
|
||||
cfg.upload_limit = Some(upload);
|
||||
cfg.download_limit = Some(download);
|
||||
})
|
||||
}) {
|
||||
Ok(Ok(())) => CtlResponse::Ok {
|
||||
message: format!(
|
||||
@@ -1931,9 +2044,14 @@ fn handle_control_conn(core: &Core, username: &str, mountpoint: &Path, stream: U
|
||||
// The request did not parse: the caller sent something malformed.
|
||||
Err(e) => CtlResponse::error(CoreError::invalid(format!("bad request: {e}"))),
|
||||
};
|
||||
let response = filter_gallery_response(response, &visibility);
|
||||
if !touched.is_empty() && !matches!(response, CtlResponse::Error { .. }) {
|
||||
core.events.publish(touched);
|
||||
}
|
||||
write_response(stream, response);
|
||||
}
|
||||
|
||||
fn write_response(mut stream: UnixStream, response: CtlResponse) {
|
||||
let mut out = match serde_json::to_vec(&response) {
|
||||
Ok(v) => v,
|
||||
Err(e) => {
|
||||
@@ -1942,10 +2060,40 @@ fn handle_control_conn(core: &Core, username: &str, mountpoint: &Path, stream: U
|
||||
}
|
||||
};
|
||||
out.push(b'\n');
|
||||
let mut stream = stream;
|
||||
let _ = stream.write_all(&out);
|
||||
}
|
||||
|
||||
fn filter_gallery_response(
|
||||
mut response: CtlResponse,
|
||||
visibility: &super::gallery::Visibility,
|
||||
) -> CtlResponse {
|
||||
let visible = |item: &pdfs_core::control::PhotoItem| !visibility.media.contains(&item.uid);
|
||||
match &mut response {
|
||||
CtlResponse::Photos { items, .. } => items.retain(visible),
|
||||
CtlResponse::Albums { items, .. } => {
|
||||
items.retain(|item| !visibility.albums.contains(&item.uid));
|
||||
for album in items {
|
||||
if album
|
||||
.cover_uid
|
||||
.as_ref()
|
||||
.is_some_and(|uid| visibility.media.contains(uid))
|
||||
{
|
||||
album.cover_uid = None;
|
||||
}
|
||||
}
|
||||
}
|
||||
CtlResponse::PhotoDuplicates { sets } | CtlResponse::PhotoSimilar { sets, .. } => {
|
||||
for set in sets.iter_mut() {
|
||||
set.retain(visible);
|
||||
}
|
||||
sets.retain(|set| set.len() > 1);
|
||||
}
|
||||
CtlResponse::PhotoLocations { items } => items.retain(|located| visible(&located.photo)),
|
||||
_ => {}
|
||||
}
|
||||
response
|
||||
}
|
||||
|
||||
/// Listen on the control socket, serving one command per connection, each on its
|
||||
/// own thread. Runs on its own thread; returns only if the listener itself fails.
|
||||
///
|
||||
|
||||
@@ -123,9 +123,7 @@ pub(crate) fn sync_root_reserved() -> pdfs_core::syncroot::Reserved {
|
||||
pub(crate) fn set_adopted_device_uid(uid: Option<&str>) -> CoreResult<()> {
|
||||
let dirs = pdfs_core::config::AppDirs::new()
|
||||
.map_err(|e| CoreError::internal(format!("config dirs: {e}")))?;
|
||||
let mut cfg = dirs.load_config();
|
||||
cfg.device_uid = uid.map(|u| u.to_string());
|
||||
dirs.save_config(&cfg)
|
||||
dirs.update_config(|cfg| cfg.device_uid = uid.map(|u| u.to_string()))
|
||||
.map_err(|e| CoreError::internal(format!("write config: {e}")))
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
//! are kept as a conflict copy rather than discarded — see
|
||||
//! [`Core::revision_conflict`].
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::fs::File;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::sync::Arc;
|
||||
@@ -53,6 +53,21 @@ use super::{
|
||||
use proton_drive_rs::proton_sdk::api::ResponseCode;
|
||||
use proton_drive_rs::proton_sdk::error::ProtonError;
|
||||
|
||||
#[derive(Debug)]
|
||||
struct TrashedMove(String);
|
||||
|
||||
impl std::fmt::Display for TrashedMove {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"‘{}’ is in Proton Drive Trash. Restore it before retrying this move.",
|
||||
self.0
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl std::error::Error for TrashedMove {}
|
||||
|
||||
const DRAIN_ACCESS_RECHECK: Duration = Duration::from_secs(5);
|
||||
|
||||
/// How long an op may stay access-deferred before the deferral is reported as a
|
||||
@@ -795,13 +810,13 @@ impl Core {
|
||||
let parent = parse_node_uid(parent_str).ok_or("rename op has an unparseable parent")?;
|
||||
let name = op.name.clone().ok_or("rename op has no name")?;
|
||||
|
||||
// The node we were asked to rename may be gone or trashed by now. Either
|
||||
// way there is nothing to rename and nothing to lose — a rename holds no
|
||||
// bytes — so the op is satisfied rather than retried forever.
|
||||
// A trashed node can be restored. Only retire the operation if the node
|
||||
// is gone entirely.
|
||||
let node = match self.fetch_node_remote(&uid)? {
|
||||
Some(n) if !n.trashed => n,
|
||||
_ => {
|
||||
warn!(%uid, name, "renamed node is gone or trashed remotely; dropping the rename");
|
||||
Some(n) if n.trashed => return Err(TrashedMove(n.name).into()),
|
||||
Some(n) => n,
|
||||
None => {
|
||||
warn!(%uid, name, "renamed node is gone remotely; dropping the rename");
|
||||
self.db.delete_op(op.id)?;
|
||||
return Ok(());
|
||||
}
|
||||
@@ -827,23 +842,38 @@ impl Core {
|
||||
// no window for the requirements to go stale between two calls —
|
||||
// the race B46 queued this op to get away from.
|
||||
let target = (node.name != name).then_some(name.as_str());
|
||||
match self.move_rename_remote(&uid, &parent, target) {
|
||||
let try_move = |target| {
|
||||
self.move_rename_remote(&uid, &parent, target).map_err(
|
||||
|error| -> Box<dyn std::error::Error> {
|
||||
if (is_gone(&error) || refusal(&error) == Some(Some(SyncIssue::Access)))
|
||||
&& let Some(name) = trashed_move_folder(
|
||||
node.parent_uid.iter().chain(std::iter::once(&parent)),
|
||||
|uid| self.fetch_node_remote(uid).ok().flatten(),
|
||||
)
|
||||
{
|
||||
return TrashedMove(name).into();
|
||||
}
|
||||
error.into()
|
||||
},
|
||||
)
|
||||
};
|
||||
match try_move(target) {
|
||||
Ok(()) => name.clone(),
|
||||
// The destination holds that name already. Landing under a
|
||||
// *different* name is the non-destructive resolution: it neither
|
||||
// clobbers their file nor drops ours, and it is visible.
|
||||
Err(e) if is_already_exists(&e) => {
|
||||
Err(e) if is_already_exists(e.as_ref()) => {
|
||||
if self.name_is_held(op, Some(&parent), &name)? {
|
||||
return Err(held_by_queued_change(&name));
|
||||
}
|
||||
// What held it may have let go since Drive answered
|
||||
// (docs/BUGS.md B144).
|
||||
match self.move_rename_remote(&uid, &parent, target) {
|
||||
match try_move(target) {
|
||||
Ok(()) => name.clone(),
|
||||
Err(e) if is_already_exists(&e) => {
|
||||
Err(e) if is_already_exists(e.as_ref()) => {
|
||||
let alt = conflict_name(&name, now_secs());
|
||||
warn!(%uid, name, alt, "destination already holds that name; using a conflict name");
|
||||
self.move_rename_remote(&uid, &parent, Some(&alt))?;
|
||||
try_move(Some(&alt))?;
|
||||
self.adopt_drained_name(&uid, &alt);
|
||||
self.log_activity(
|
||||
ActivityKind::Rename,
|
||||
@@ -853,7 +883,7 @@ impl Core {
|
||||
);
|
||||
alt
|
||||
}
|
||||
Err(e) => return Err(e.into()),
|
||||
Err(e) => return Err(e),
|
||||
}
|
||||
}
|
||||
// The destination folder is gone. Leaving the node in its current
|
||||
@@ -862,7 +892,7 @@ impl Core {
|
||||
// the user chose still applies there. Retrying the move could
|
||||
// only fail again — the folder is not coming back — and would
|
||||
// wedge the queue.
|
||||
Err(e) if is_gone(&e) => {
|
||||
Err(e) if is_gone(e.as_ref()) => {
|
||||
warn!(%uid, name, %parent, "move destination is gone; leaving the node where it is");
|
||||
let landed = match self.drain_rename_in_place(
|
||||
op,
|
||||
@@ -885,7 +915,7 @@ impl Core {
|
||||
);
|
||||
landed
|
||||
}
|
||||
Err(e) => return Err(e.into()),
|
||||
Err(e) => return Err(e),
|
||||
}
|
||||
};
|
||||
self.db.delete_op(op.id)?;
|
||||
@@ -1349,7 +1379,11 @@ impl Core {
|
||||
parent: Option<&NodeUid>,
|
||||
name: &str,
|
||||
) -> Result<bool, Box<dyn std::error::Error>> {
|
||||
if self.db.has_pending_trash_named(name)? {
|
||||
let parent_uid = parent.map(NodeUid::to_string);
|
||||
if self
|
||||
.db
|
||||
.has_pending_trash_named(name, parent_uid.as_deref())?
|
||||
{
|
||||
return Ok(true);
|
||||
}
|
||||
if op.attempts >= NAME_HOLD_ATTEMPTS {
|
||||
@@ -2695,6 +2729,29 @@ fn moved_elsewhere(meta: &RenameMeta, node: &Node, parent: &NodeUid, name: &str)
|
||||
!at(&meta.original_parent_uid, original_name) && !at(&parent.to_string(), name)
|
||||
}
|
||||
|
||||
/// A child can have a normal metadata record even when an ancestor is trashed.
|
||||
/// Check both live parent chains before interpreting a refused move as an
|
||||
/// access problem. Shared ancestors only need to be fetched once.
|
||||
fn trashed_move_folder<'a>(
|
||||
parents: impl IntoIterator<Item = &'a NodeUid>,
|
||||
mut fetch: impl FnMut(&NodeUid) -> Option<Node>,
|
||||
) -> Option<String> {
|
||||
let mut seen = HashSet::new();
|
||||
for parent in parents {
|
||||
let mut next = Some(parent.clone());
|
||||
while let Some(uid) = next.take()
|
||||
&& seen.insert(uid.clone())
|
||||
&& let Some(node) = fetch(&uid)
|
||||
{
|
||||
if node.trashed {
|
||||
return Some(node.name);
|
||||
}
|
||||
next = node.parent_uid;
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
/// The answer from Drive somewhere in `e`'s chain, if it got that far.
|
||||
fn proton_error<'e>(e: &'e (dyn std::error::Error + 'static)) -> Option<&'e ProtonError> {
|
||||
std::iter::successors(Some(e), |e| e.source()).find_map(|e| e.downcast_ref::<ProtonError>())
|
||||
@@ -2704,6 +2761,9 @@ fn proton_error<'e>(e: &'e (dyn std::error::Error + 'static)) -> Option<&'e Prot
|
||||
/// could not be reached, which says nothing; otherwise the issue Drive's answer
|
||||
/// is, or `Some(None)` for a failure that is not a refusal.
|
||||
fn refusal(e: &(dyn std::error::Error + 'static)) -> Option<Option<SyncIssue>> {
|
||||
if e.is::<TrashedMove>() {
|
||||
return Some(Some(SyncIssue::Trashed));
|
||||
}
|
||||
let proton = proton_error(e)?;
|
||||
// A refused session refuses everything, so it says nothing about this
|
||||
// op either; the mount is offline for it (`Core::lost_link`).
|
||||
@@ -3111,6 +3171,31 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_refused_move_identifies_a_trashed_ancestor_on_either_side() {
|
||||
let source = folder_node("source", Some("old"));
|
||||
let destination = folder_node("destination", Some("new"));
|
||||
let mut old = folder_node("old", None);
|
||||
let mut new = folder_node("new", None);
|
||||
let find = |old: &Node, new: &Node| {
|
||||
trashed_move_folder([&source.uid, &destination.uid], |uid| {
|
||||
[&source, &destination, old, new]
|
||||
.into_iter()
|
||||
.find(|node| node.uid == *uid)
|
||||
.cloned()
|
||||
})
|
||||
};
|
||||
old.trashed = true;
|
||||
assert_eq!(find(&old, &new).as_deref(), Some("old"));
|
||||
old.trashed = false;
|
||||
new.trashed = true;
|
||||
let error = TrashedMove(find(&old, &new).unwrap());
|
||||
assert_eq!(refusal(&error), Some(Some(SyncIssue::Trashed)));
|
||||
assert!(error.to_string().contains("‘new’"));
|
||||
new.trashed = false;
|
||||
assert_eq!(find(&old, &new), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn queued_cross_parent_rename_retains_viewer_source_authority_after_local_move() {
|
||||
use std::sync::atomic::{AtomicU64, Ordering};
|
||||
|
||||
@@ -2372,17 +2372,19 @@ impl ProtonFs {
|
||||
}
|
||||
}
|
||||
}
|
||||
// Offline: queue it. Trashing is the one mutation a user expects to work
|
||||
// regardless — the file is gone from their point of view the moment the
|
||||
// command returns. The same when the network goes
|
||||
// away under the remote call below.
|
||||
// Queue a folder trash while Drive still holds children that were moved
|
||||
// out locally. The drain waits for those moves before sending it.
|
||||
let queue_it = |reply: ReplyEmpty| match self.core.queue_trash(&uid, name, open_now) {
|
||||
Ok(()) => reply.ok(),
|
||||
Err(e) => reply.error(e),
|
||||
};
|
||||
if !self.core.sends_inline() {
|
||||
queue_it(reply);
|
||||
return;
|
||||
return queue_it(reply);
|
||||
}
|
||||
match self.core.has_pending_moves_out_of(&uid) {
|
||||
Ok(false) => {}
|
||||
Ok(true) => return queue_it(reply),
|
||||
Err(error) => return reply.error(error),
|
||||
}
|
||||
if let Err(e) = self.core.require_uid_writable(&uid) {
|
||||
reply.error(e);
|
||||
|
||||
@@ -0,0 +1,653 @@
|
||||
//! Host Proton Gallery's account and catalog services in the Drive daemon.
|
||||
|
||||
mod video;
|
||||
|
||||
use std::collections::HashSet;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::{
|
||||
Arc, RwLock,
|
||||
atomic::{AtomicU64, Ordering},
|
||||
};
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use pdfs_core::control::{
|
||||
GalleryAction, GalleryAlbum, GalleryFolder, GalleryPlace, PhotoItem, PhotoKind, Response,
|
||||
};
|
||||
use pdfs_core::{CoreError, CoreResult};
|
||||
use proton_drive_rs::proton_sdk::session::ProtonApiSession;
|
||||
use proton_gallery_app_rs::{App, View};
|
||||
use proton_gallery_rs::CancellationToken;
|
||||
use proton_gallery_rs::model::{AssetKey, SourceId};
|
||||
use tokio::sync::{Mutex, Notify, OnceCell};
|
||||
|
||||
use super::{Core, NodeUid, parse_uid};
|
||||
|
||||
pub(super) struct Gallery {
|
||||
root: PathBuf,
|
||||
session: ProtonApiSession,
|
||||
cancel: CancellationToken,
|
||||
app: OnceCell<App>,
|
||||
checked: Mutex<Option<Instant>>,
|
||||
visibility: RwLock<Option<Arc<Visibility>>>,
|
||||
refresh: Notify,
|
||||
access: AtomicU64,
|
||||
video: video::Server,
|
||||
}
|
||||
|
||||
#[derive(Default, PartialEq, Eq)]
|
||||
pub(super) struct Visibility {
|
||||
pub(super) media: HashSet<String>,
|
||||
pub(super) albums: HashSet<String>,
|
||||
}
|
||||
|
||||
impl Visibility {
|
||||
pub(super) fn permits(&self, uid: &str) -> CoreResult<()> {
|
||||
if self.media.contains(uid) || self.albums.contains(uid) {
|
||||
return Err(CoreError::invalid("Unlock hidden albums to open this item"));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl Gallery {
|
||||
pub(super) fn new(root: PathBuf, session: ProtonApiSession) -> Self {
|
||||
Self {
|
||||
root,
|
||||
session,
|
||||
cancel: CancellationToken::new(),
|
||||
app: OnceCell::new(),
|
||||
checked: Mutex::new(None),
|
||||
visibility: RwLock::default(),
|
||||
refresh: Notify::new(),
|
||||
access: AtomicU64::new(0),
|
||||
video: video::Server::default(),
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn cancel(&self) {
|
||||
self.cancel.cancel();
|
||||
self.video.close_all();
|
||||
}
|
||||
|
||||
async fn app(&self, core: &Core) -> CoreResult<&App> {
|
||||
self.app
|
||||
.get_or_try_init(|| async {
|
||||
App::open_hosted(
|
||||
self.root.clone(),
|
||||
self.session.clone(),
|
||||
core.client.clone(),
|
||||
self.cancel.child_token(),
|
||||
)
|
||||
.await
|
||||
.map_err(gallery_error)
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
||||
async fn ensure_visibility(
|
||||
&self,
|
||||
core: &Core,
|
||||
app: &App,
|
||||
force: bool,
|
||||
) -> CoreResult<Arc<Visibility>> {
|
||||
if self.cancel.is_cancelled() {
|
||||
return Err(CoreError::remote("The Gallery session expired"));
|
||||
}
|
||||
let mut checked = self.checked.lock().await;
|
||||
if !force
|
||||
&& let Some(instant) = *checked
|
||||
&& instant.elapsed()
|
||||
< if self.snapshot().is_some() {
|
||||
Duration::from_secs(60)
|
||||
} else {
|
||||
Duration::from_secs(5)
|
||||
}
|
||||
{
|
||||
return self.snapshot().ok_or_else(visibility_loading);
|
||||
}
|
||||
if self.snapshot().is_none()
|
||||
&& app
|
||||
.gallery_visibility_cached()
|
||||
.await
|
||||
.map_err(gallery_error)?
|
||||
{
|
||||
self.publish_visibility(core, self.read_visibility(core, app).await?);
|
||||
}
|
||||
let started = Instant::now();
|
||||
let result = tokio::select! {
|
||||
biased;
|
||||
_ = self.cancel.cancelled() => Err(CoreError::remote("The Gallery session expired")),
|
||||
result = tokio::time::timeout(Duration::from_secs(20), async {
|
||||
app.refresh_gallery_configuration(false).await.map_err(gallery_error)?;
|
||||
self.read_visibility(core, app).await
|
||||
}) => result.unwrap_or_else(|_| Err(CoreError::remote("Gallery visibility check timed out"))),
|
||||
};
|
||||
tracing::debug!(
|
||||
elapsed_ms = started.elapsed().as_millis() as u64,
|
||||
success = result.is_ok(),
|
||||
"Gallery visibility refresh"
|
||||
);
|
||||
*checked = Some(Instant::now());
|
||||
if let Ok(visibility) = result {
|
||||
self.publish_visibility(core, visibility.clone());
|
||||
return Ok(visibility);
|
||||
}
|
||||
if !force && let Some(visibility) = self.snapshot() {
|
||||
return Ok(visibility);
|
||||
}
|
||||
result
|
||||
}
|
||||
|
||||
fn snapshot(&self) -> Option<Arc<Visibility>> {
|
||||
self.visibility
|
||||
.read()
|
||||
.unwrap_or_else(|e| e.into_inner())
|
||||
.clone()
|
||||
}
|
||||
|
||||
fn publish_visibility(&self, core: &Core, visibility: Arc<Visibility>) {
|
||||
let mut snapshot = self.visibility.write().unwrap_or_else(|e| e.into_inner());
|
||||
if snapshot.as_ref() != Some(&visibility) {
|
||||
*snapshot = Some(visibility);
|
||||
drop(snapshot);
|
||||
self.video.close_all();
|
||||
core.events
|
||||
.publish(&[pdfs_core::control::Topic::GalleryVisibilitySynced]);
|
||||
}
|
||||
}
|
||||
|
||||
async fn read_visibility(&self, core: &Core, app: &App) -> CoreResult<Arc<Visibility>> {
|
||||
let account = self.account()?;
|
||||
let mut visibility = Visibility::default();
|
||||
for (volume, node) in app
|
||||
.catalog
|
||||
.hidden_assets(account.clone())
|
||||
.await
|
||||
.map_err(gallery_error)?
|
||||
{
|
||||
visibility
|
||||
.media
|
||||
.insert(NodeUid::new(volume.into(), node.into()).to_string());
|
||||
}
|
||||
visibility.media.extend(
|
||||
core.db
|
||||
.photo_group_members_for(&visibility.media)
|
||||
.map_err(CoreError::from)?,
|
||||
);
|
||||
for album in app
|
||||
.catalog
|
||||
.hidden_configuration_albums(account)
|
||||
.await
|
||||
.map_err(gallery_error)?
|
||||
{
|
||||
visibility.albums.insert(
|
||||
NodeUid::new(album.volume.as_str().into(), album.node.as_str().into()).to_string(),
|
||||
);
|
||||
}
|
||||
Ok(Arc::new(visibility))
|
||||
}
|
||||
|
||||
fn account(&self) -> CoreResult<proton_gallery_rs::model::AccountId> {
|
||||
proton_gallery_rs::model::AccountId::new(self.session.user_id().as_str())
|
||||
.map_err(gallery_error)
|
||||
}
|
||||
|
||||
async fn page(
|
||||
&self,
|
||||
app: &App,
|
||||
album: Option<GalleryPlace>,
|
||||
proton: bool,
|
||||
access: Option<u64>,
|
||||
offset: usize,
|
||||
limit: usize,
|
||||
) -> CoreResult<Response> {
|
||||
let private = access.is_some();
|
||||
let parent = album
|
||||
.as_ref()
|
||||
.map(|a| (a.gallery.as_str(), a.album.as_str()));
|
||||
let mut albums = Vec::new();
|
||||
if offset == 0 && !proton {
|
||||
if private && parent.is_none() {
|
||||
albums.extend(
|
||||
app.photo_albums_with_hidden(true)
|
||||
.await
|
||||
.map_err(gallery_error)?
|
||||
.into_iter()
|
||||
.filter(|entry| entry.settings.hidden)
|
||||
.map(|entry| gallery_album(entry, true)),
|
||||
);
|
||||
albums.extend(
|
||||
app.hidden_drive_albums()
|
||||
.await
|
||||
.map_err(gallery_error)?
|
||||
.into_iter()
|
||||
.map(|entry| gallery_album(entry, false)),
|
||||
);
|
||||
} else {
|
||||
albums.extend(
|
||||
app.drive_albums(parent, private)
|
||||
.await
|
||||
.map_err(gallery_error)?
|
||||
.into_iter()
|
||||
.map(|entry| gallery_album(entry, false)),
|
||||
);
|
||||
}
|
||||
}
|
||||
let (items, total) = if let Some(GalleryPlace { gallery, album }) = album {
|
||||
let view = if proton && private {
|
||||
let id = SourceId::new(&album).map_err(gallery_error)?;
|
||||
if !app
|
||||
.catalog
|
||||
.album_settings(id)
|
||||
.await
|
||||
.map_err(gallery_error)?
|
||||
.hidden
|
||||
{
|
||||
return Err(CoreError::not_found("Hidden album"));
|
||||
}
|
||||
View::PhotoAlbum(album)
|
||||
} else {
|
||||
if private
|
||||
&& !app
|
||||
.catalog
|
||||
.drive_album_is_private(
|
||||
SourceId::new(&gallery).map_err(gallery_error)?,
|
||||
SourceId::new(&album).map_err(gallery_error)?,
|
||||
)
|
||||
.await
|
||||
.map_err(gallery_error)?
|
||||
{
|
||||
return Err(CoreError::not_found("Hidden gallery folder"));
|
||||
}
|
||||
View::DriveAlbum { gallery, album }
|
||||
};
|
||||
let outline = app
|
||||
.outline_with_visibility(view, false, private)
|
||||
.await
|
||||
.map_err(gallery_error)?;
|
||||
let total = outline.len();
|
||||
let items = app
|
||||
.outline_items(&outline, offset.min(total), limit.clamp(1, 250))
|
||||
.await
|
||||
.map_err(gallery_error)?
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.map(|item| PhotoItem {
|
||||
uid: asset_uid(&item.key),
|
||||
capture_time: item.sort_time,
|
||||
thumb_path: None,
|
||||
name: Some(item.name),
|
||||
ratio: item.aspect_ratio,
|
||||
no_thumb: false,
|
||||
kind: if item.is_video {
|
||||
PhotoKind::Video
|
||||
} else {
|
||||
PhotoKind::Photo
|
||||
},
|
||||
favorite: item.favorite,
|
||||
group_size: 1,
|
||||
has_raw: false,
|
||||
place_id: None,
|
||||
})
|
||||
.collect();
|
||||
(items, total)
|
||||
} else {
|
||||
(Vec::new(), 0)
|
||||
};
|
||||
self.require_access(access)?;
|
||||
Ok(Response::GalleryPage {
|
||||
albums,
|
||||
items,
|
||||
total,
|
||||
})
|
||||
}
|
||||
|
||||
fn lock(&self) {
|
||||
let _ = self
|
||||
.access
|
||||
.try_update(Ordering::SeqCst, Ordering::SeqCst, |value| {
|
||||
Some((value | 1).wrapping_add(1))
|
||||
});
|
||||
self.video.close_all();
|
||||
}
|
||||
|
||||
fn private_access(&self) -> CoreResult<u64> {
|
||||
let access = self.access.load(Ordering::SeqCst);
|
||||
if access & 1 == 0 {
|
||||
return Err(CoreError::invalid("Unlock hidden albums to open this item"));
|
||||
}
|
||||
Ok(access)
|
||||
}
|
||||
|
||||
fn require_access(&self, access: Option<u64>) -> CoreResult<()> {
|
||||
if let Some(access) = access
|
||||
&& self.private_access()? != access
|
||||
{
|
||||
return Err(CoreError::invalid("Hidden albums were locked"));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(super) async fn poll(self: Arc<Self>, core: Core) {
|
||||
loop {
|
||||
tokio::select! {
|
||||
biased;
|
||||
_ = self.cancel.cancelled() => break,
|
||||
_ = self.refresh.notified() => {},
|
||||
_ = tokio::time::sleep(Duration::from_secs(60)) => {}
|
||||
}
|
||||
if let Ok(Ok(app)) = tokio::time::timeout(Duration::from_secs(5), self.app(&core)).await
|
||||
{
|
||||
let _ = self.ensure_visibility(&core, app, false).await;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn asset(&self, uid: &NodeUid) -> CoreResult<AssetKey> {
|
||||
Ok(AssetKey {
|
||||
account: self.account()?,
|
||||
volume: proton_gallery_rs::model::VolumeId::new(uid.volume_id.as_str())
|
||||
.map_err(gallery_error)?,
|
||||
node: proton_gallery_rs::model::NodeId::new(uid.link_id.as_str())
|
||||
.map_err(gallery_error)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fn gallery_album(entry: proton_gallery_rs::library::Album, proton: bool) -> GalleryAlbum {
|
||||
GalleryAlbum {
|
||||
place: GalleryPlace {
|
||||
gallery: entry.gallery.to_string(),
|
||||
album: entry.source.id.to_string(),
|
||||
},
|
||||
proton,
|
||||
folder: GalleryFolder {
|
||||
uid: NodeUid::new(
|
||||
entry.source.volume.as_str().into(),
|
||||
entry.source.root.as_str().into(),
|
||||
)
|
||||
.to_string(),
|
||||
name: entry.settings.title.unwrap_or(entry.source.label),
|
||||
},
|
||||
cover: entry.cover.map(|asset| asset_uid(&asset.key)),
|
||||
items: entry.direct_items,
|
||||
folders: entry.child_albums,
|
||||
hidden: entry.settings.hidden,
|
||||
}
|
||||
}
|
||||
|
||||
fn gallery_error(error: impl std::fmt::Display) -> CoreError {
|
||||
CoreError::remote(error.to_string())
|
||||
}
|
||||
|
||||
fn uid(value: &str) -> CoreResult<NodeUid> {
|
||||
parse_uid(value).ok_or_else(|| CoreError::invalid("Invalid gallery node"))
|
||||
}
|
||||
|
||||
fn done() -> Response {
|
||||
Response::Ok {
|
||||
message: "Gallery updated".into(),
|
||||
}
|
||||
}
|
||||
|
||||
fn asset_uid(asset: &AssetKey) -> String {
|
||||
NodeUid::new(asset.volume.as_str().into(), asset.node.as_str().into()).to_string()
|
||||
}
|
||||
|
||||
fn visibility_loading() -> CoreError {
|
||||
CoreError::new(
|
||||
pdfs_core::control::ErrorKind::Offline,
|
||||
"Gallery visibility is loading. Try again shortly.",
|
||||
)
|
||||
}
|
||||
|
||||
impl Core {
|
||||
pub(super) fn cached_gallery_visibility(&self) -> CoreResult<Arc<Visibility>> {
|
||||
if self.gallery.is_none() {
|
||||
return Ok(Arc::default());
|
||||
}
|
||||
let gallery = self.gallery_host()?;
|
||||
match gallery.snapshot() {
|
||||
Some(snapshot) => Ok(snapshot),
|
||||
None => {
|
||||
gallery.refresh.notify_one();
|
||||
Err(visibility_loading())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn gallery_visibility(&self) -> CoreResult<Arc<Visibility>> {
|
||||
if self.gallery.is_none() {
|
||||
return Ok(Arc::default());
|
||||
}
|
||||
let gallery = self.gallery_host()?;
|
||||
self.rt.block_on(async {
|
||||
let app = gallery.app(self).await?;
|
||||
gallery.ensure_visibility(self, app, false).await
|
||||
})
|
||||
}
|
||||
|
||||
fn gallery_host(&self) -> CoreResult<&Gallery> {
|
||||
self.gallery
|
||||
.as_deref()
|
||||
.filter(|gallery| !gallery.cancel.is_cancelled())
|
||||
.ok_or_else(|| CoreError::remote("The Gallery session is unavailable"))
|
||||
}
|
||||
|
||||
pub(super) fn authenticate_hidden_gallery(
|
||||
&self,
|
||||
stream: &std::os::unix::net::UnixStream,
|
||||
) -> CoreResult<Response> {
|
||||
let gallery = self.gallery_host()?;
|
||||
let access = gallery.access.load(Ordering::SeqCst);
|
||||
let peer = rustix::net::sockopt::socket_peercred(stream)
|
||||
.map_err(|_| CoreError::invalid("Couldn’t identify the authentication requester."))?;
|
||||
if peer.uid != rustix::process::geteuid() {
|
||||
return Err(CoreError::invalid(
|
||||
"Use your Linux sign-in to unlock Hidden albums.",
|
||||
));
|
||||
}
|
||||
let subject = proton_gallery_app_rs::desktop_auth::Subject::new(
|
||||
peer.pid.as_raw_nonzero().get() as u32,
|
||||
peer.uid.as_raw(),
|
||||
)
|
||||
.map_err(gallery_error)?;
|
||||
self.rt
|
||||
.block_on(subject.authenticate("io.narl.proton-drive-linux.unlock-hidden-albums"))
|
||||
.map_err(gallery_error)?;
|
||||
if gallery.cancel.is_cancelled() {
|
||||
return Err(CoreError::invalid("The Gallery session has ended."));
|
||||
}
|
||||
gallery
|
||||
.access
|
||||
.compare_exchange(access, access | 1, Ordering::SeqCst, Ordering::SeqCst)
|
||||
.map_err(|_| CoreError::invalid("Hidden albums were locked"))?;
|
||||
Ok(done())
|
||||
}
|
||||
|
||||
pub(super) fn drive_gallery(&self, action: GalleryAction) -> CoreResult<Response> {
|
||||
let gallery = self.gallery_host()?;
|
||||
let action = match action {
|
||||
GalleryAction::Lock => {
|
||||
gallery.lock();
|
||||
return Ok(done());
|
||||
}
|
||||
other => other,
|
||||
};
|
||||
self.rt.block_on(async {
|
||||
let app = gallery.app(self).await?;
|
||||
gallery
|
||||
.ensure_visibility(self, app, matches!(action, GalleryAction::Refresh))
|
||||
.await?;
|
||||
match action {
|
||||
GalleryAction::AuthenticateHidden | GalleryAction::Lock => unreachable!(),
|
||||
GalleryAction::List {
|
||||
album,
|
||||
offset,
|
||||
limit,
|
||||
} => gallery.page(app, album, false, None, offset, limit).await,
|
||||
GalleryAction::PrivateList {
|
||||
album,
|
||||
proton,
|
||||
offset,
|
||||
limit,
|
||||
} => {
|
||||
let access = gallery.private_access()?;
|
||||
gallery
|
||||
.page(app, album, proton, Some(access), offset, limit)
|
||||
.await
|
||||
}
|
||||
GalleryAction::Folders { parent } => {
|
||||
let list = app
|
||||
.browse_drive_folders(parent.as_deref().map(uid).transpose()?)
|
||||
.await
|
||||
.map_err(gallery_error)?;
|
||||
Ok(Response::GalleryFolders {
|
||||
folders: list
|
||||
.children
|
||||
.into_iter()
|
||||
.map(|folder| GalleryFolder {
|
||||
uid: folder.uid.to_string(),
|
||||
name: folder.name,
|
||||
})
|
||||
.collect(),
|
||||
})
|
||||
}
|
||||
GalleryAction::Add { uid: node } => {
|
||||
app.add_drive_folder(uid(&node)?)
|
||||
.await
|
||||
.map_err(gallery_error)?;
|
||||
gallery.ensure_visibility(self, app, true).await?;
|
||||
Ok(done())
|
||||
}
|
||||
GalleryAction::Remove { gallery: id } => {
|
||||
app.forget_drive_gallery(SourceId::new(id).map_err(gallery_error)?)
|
||||
.await
|
||||
.map_err(gallery_error)?;
|
||||
gallery.ensure_visibility(self, app, true).await?;
|
||||
Ok(done())
|
||||
}
|
||||
GalleryAction::Refresh => {
|
||||
for album in app.drive_albums(None, true).await.map_err(gallery_error)? {
|
||||
let root = NodeUid::new(
|
||||
album.source.volume.as_str().into(),
|
||||
album.source.root.as_str().into(),
|
||||
);
|
||||
app.scan_drive_folder(root).await.map_err(gallery_error)?;
|
||||
}
|
||||
gallery.ensure_visibility(self, app, true).await?;
|
||||
Ok(done())
|
||||
}
|
||||
GalleryAction::Cover { album, uid: node } => {
|
||||
let id = SourceId::new(&album.album).map_err(gallery_error)?;
|
||||
let root = SourceId::new(&album.gallery).map_err(gallery_error)?;
|
||||
app.checked_album(album.gallery, album.album)
|
||||
.await
|
||||
.map_err(gallery_error)?;
|
||||
let access = if app
|
||||
.catalog
|
||||
.drive_album_is_private(root.clone(), id.clone())
|
||||
.await
|
||||
.map_err(gallery_error)?
|
||||
{
|
||||
Some(gallery.private_access()?)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let mut settings = app
|
||||
.catalog
|
||||
.album_settings(id.clone())
|
||||
.await
|
||||
.map_err(gallery_error)?;
|
||||
gallery.require_access(access)?;
|
||||
settings.cover = Some(gallery.asset(&uid(&node)?)?);
|
||||
app.catalog
|
||||
.set_album_settings_at(Some(root), id, settings)
|
||||
.await
|
||||
.map_err(gallery_error)?;
|
||||
gallery.ensure_visibility(self, app, true).await?;
|
||||
Ok(done())
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub(super) fn open_gallery_video(&self, node: &str, private: bool) -> CoreResult<Response> {
|
||||
let gallery = self.gallery_host()?;
|
||||
let uid = uid(node)?;
|
||||
self.rt.block_on(async {
|
||||
let app = gallery.app(self).await?;
|
||||
let visibility = gallery.ensure_visibility(self, app, false).await?;
|
||||
let access = if private {
|
||||
Some(gallery.private_access()?)
|
||||
} else {
|
||||
visibility.permits(node)?;
|
||||
None
|
||||
};
|
||||
let stream = app
|
||||
.stream_video(&gallery.asset(&uid)?)
|
||||
.await
|
||||
.map_err(gallery_error)?;
|
||||
let response = gallery.video.open(stream, &gallery.cancel).await?;
|
||||
if let Err(error) = gallery.require_access(access) {
|
||||
if let Response::GalleryVideo { token, .. } = &response {
|
||||
gallery.video.close(token);
|
||||
}
|
||||
return Err(error);
|
||||
}
|
||||
Ok(response)
|
||||
})
|
||||
}
|
||||
|
||||
pub(super) fn gallery_image(&self, node: &str) -> CoreResult<Response> {
|
||||
use base64::{Engine, engine::general_purpose::STANDARD};
|
||||
let gallery = self.gallery_host()?;
|
||||
let access = gallery.private_access()?;
|
||||
let asset = gallery.asset(&uid(node)?)?;
|
||||
self.rt.block_on(async {
|
||||
let app = gallery.app(self).await?;
|
||||
let bytes = tokio::time::timeout(Duration::from_secs(30), async {
|
||||
if let Some(bytes) = app.preview(&asset).await? {
|
||||
Ok(bytes)
|
||||
} else {
|
||||
app.original_in_memory(&asset, 8 * 1024 * 1024).await
|
||||
}
|
||||
})
|
||||
.await
|
||||
.map_err(|_| CoreError::remote("Proton took too long to open this photo"))?
|
||||
.map_err(gallery_error)?;
|
||||
gallery.require_access(Some(access))?;
|
||||
Ok(Response::GalleryThumbnail {
|
||||
data: Some(STANDARD.encode(bytes)),
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
pub(super) fn close_gallery_video(&self, token: &str) -> CoreResult<Response> {
|
||||
self.gallery_host()?.video.close(token);
|
||||
Ok(done())
|
||||
}
|
||||
|
||||
pub(super) fn gallery_thumbnail(&self, node: &str, private: bool) -> CoreResult<Response> {
|
||||
use base64::{Engine, engine::general_purpose::STANDARD};
|
||||
let gallery = self.gallery_host()?;
|
||||
let asset = gallery.asset(&uid(node)?)?;
|
||||
self.rt.block_on(async {
|
||||
let app = gallery.app(self).await?;
|
||||
let visibility = gallery.ensure_visibility(self, app, false).await?;
|
||||
let access = if private {
|
||||
Some(gallery.private_access()?)
|
||||
} else {
|
||||
visibility.permits(node)?;
|
||||
None
|
||||
};
|
||||
let data = app
|
||||
.thumbnail(&asset)
|
||||
.await
|
||||
.map_err(gallery_error)?
|
||||
.map(|bytes| STANDARD.encode(bytes));
|
||||
gallery.require_access(access)?;
|
||||
Ok(Response::GalleryThumbnail { data })
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,205 @@
|
||||
use std::{collections::VecDeque, io, sync::Arc, time::Duration};
|
||||
|
||||
use base64::{Engine, engine::general_purpose::URL_SAFE_NO_PAD};
|
||||
use http_body_util::{BodyExt, Empty, StreamBody, combinators::UnsyncBoxBody};
|
||||
use hyper::{
|
||||
Method, Request, Response, StatusCode,
|
||||
body::{Bytes, Frame, Incoming},
|
||||
header,
|
||||
server::conn::http1,
|
||||
service::service_fn,
|
||||
};
|
||||
use hyper_util::rt::TokioIo;
|
||||
use pdfs_core::{CoreResult, control::Response as ControlResponse};
|
||||
use proton_gallery_app_rs::video::VideoStream;
|
||||
use proton_gallery_rs::CancellationToken;
|
||||
use tokio::net::TcpListener;
|
||||
|
||||
type Body = UnsyncBoxBody<Bytes, io::Error>;
|
||||
|
||||
const LEASE: Duration = Duration::from_secs(4 * 60 * 60);
|
||||
const MAX_STREAMS: usize = 4;
|
||||
const CHUNK: u32 = 256 * 1024;
|
||||
|
||||
#[derive(Default)]
|
||||
pub(super) struct Server {
|
||||
active: parking_lot::Mutex<VecDeque<(String, CancellationToken)>>,
|
||||
}
|
||||
|
||||
impl Server {
|
||||
pub(super) fn close(&self, token: &str) {
|
||||
let mut active = self.active.lock();
|
||||
if let Some(index) = active.iter().position(|(id, _)| id == token)
|
||||
&& let Some((_, cancel)) = active.remove(index)
|
||||
{
|
||||
cancel.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn close_all(&self) {
|
||||
for (_, cancel) in self.active.lock().drain(..) {
|
||||
cancel.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) async fn open(
|
||||
&self,
|
||||
stream: Arc<VideoStream>,
|
||||
account: &CancellationToken,
|
||||
) -> CoreResult<ControlResponse> {
|
||||
let listener = TcpListener::bind((std::net::Ipv4Addr::LOCALHOST, 0))
|
||||
.await
|
||||
.map_err(super::gallery_error)?;
|
||||
let address = listener.local_addr().map_err(super::gallery_error)?;
|
||||
let mut nonce = [0; 32];
|
||||
getrandom::fill(&mut nonce).map_err(super::gallery_error)?;
|
||||
let token = URL_SAFE_NO_PAD.encode(nonce);
|
||||
let path: Arc<str> = format!("/{token}").into();
|
||||
let cancel = account.child_token();
|
||||
{
|
||||
let mut active = self.active.lock();
|
||||
active.retain(|(_, cancel)| !cancel.is_cancelled());
|
||||
if active.len() >= MAX_STREAMS
|
||||
&& let Some((_, oldest)) = active.pop_front()
|
||||
{
|
||||
oldest.cancel();
|
||||
}
|
||||
active.push_back((token.clone(), cancel.clone()));
|
||||
}
|
||||
let size = stream.length();
|
||||
tokio::spawn(async move {
|
||||
let mut connections = tokio::task::JoinSet::new();
|
||||
let lifetime = tokio::time::sleep(LEASE);
|
||||
tokio::pin!(lifetime);
|
||||
loop {
|
||||
tokio::select! {
|
||||
biased;
|
||||
_ = cancel.cancelled() => break,
|
||||
_ = &mut lifetime => break,
|
||||
_ = connections.join_next(), if !connections.is_empty() => {},
|
||||
incoming = listener.accept(), if connections.len() < 8 => {
|
||||
let Ok((socket, _)) = incoming else { break };
|
||||
let stream = stream.clone();
|
||||
let path = path.clone();
|
||||
connections.spawn(async move {
|
||||
let service = service_fn(move |request| reply(request, stream.clone(), path.clone()));
|
||||
let _ = http1::Builder::new()
|
||||
.timer(hyper_util::rt::TokioTimer::new())
|
||||
.header_read_timeout(Duration::from_secs(10))
|
||||
.keep_alive(false)
|
||||
.serve_connection(TokioIo::new(socket), service).await;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
stream.stop();
|
||||
cancel.cancel();
|
||||
connections.abort_all();
|
||||
});
|
||||
Ok(ControlResponse::GalleryVideo {
|
||||
url: format!("http://{address}/{token}"),
|
||||
token,
|
||||
size,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fn range(value: Option<&str>, size: u64) -> Option<(u64, u64)> {
|
||||
let Some(value) = value else {
|
||||
return Some((0, size));
|
||||
};
|
||||
let (first, last) = value.strip_prefix("bytes=")?.split_once('-')?;
|
||||
if first.is_empty() {
|
||||
let suffix = last.parse::<u64>().ok()?.min(size);
|
||||
return (suffix > 0).then_some((size - suffix, size));
|
||||
}
|
||||
let start = first.parse::<u64>().ok()?;
|
||||
let end = if last.is_empty() {
|
||||
size
|
||||
} else {
|
||||
last.parse::<u64>().ok()?.saturating_add(1).min(size)
|
||||
};
|
||||
(start < end).then_some((start, end))
|
||||
}
|
||||
|
||||
fn empty() -> Body {
|
||||
Empty::new().map_err(|never| match never {}).boxed_unsync()
|
||||
}
|
||||
|
||||
async fn reply(
|
||||
request: Request<Incoming>,
|
||||
stream: Arc<VideoStream>,
|
||||
path: Arc<str>,
|
||||
) -> Result<Response<Body>, hyper::http::Error> {
|
||||
let response = Response::builder().header(header::CACHE_CONTROL, "no-store");
|
||||
if request
|
||||
.uri()
|
||||
.path_and_query()
|
||||
.is_none_or(|actual| actual.as_str() != path.as_ref())
|
||||
{
|
||||
return response.status(StatusCode::NOT_FOUND).body(empty());
|
||||
}
|
||||
if !matches!(*request.method(), Method::HEAD | Method::GET) {
|
||||
return response
|
||||
.status(StatusCode::METHOD_NOT_ALLOWED)
|
||||
.body(empty());
|
||||
}
|
||||
let size = stream.length();
|
||||
let requested = request.headers().get(header::RANGE);
|
||||
let parsed = match requested {
|
||||
Some(value) => value
|
||||
.to_str()
|
||||
.ok()
|
||||
.and_then(|value| range(Some(value), size)),
|
||||
None => range(None, size),
|
||||
};
|
||||
let Some((start, end)) = parsed else {
|
||||
return response
|
||||
.status(StatusCode::RANGE_NOT_SATISFIABLE)
|
||||
.header(header::CONTENT_RANGE, format!("bytes */{size}"))
|
||||
.body(empty());
|
||||
};
|
||||
let response = response
|
||||
.header(header::ACCEPT_RANGES, "bytes")
|
||||
.header(header::CONTENT_LENGTH, end - start)
|
||||
.header(header::CONTENT_TYPE, "application/octet-stream");
|
||||
let response = if requested.is_some() {
|
||||
response.status(StatusCode::PARTIAL_CONTENT).header(
|
||||
header::CONTENT_RANGE,
|
||||
format!("bytes {start}-{}/{size}", end - 1),
|
||||
)
|
||||
} else {
|
||||
response
|
||||
};
|
||||
if request.method() == Method::HEAD {
|
||||
return response.body(empty());
|
||||
}
|
||||
let body = futures::stream::try_unfold((stream, start), move |(stream, at)| async move {
|
||||
if at == end {
|
||||
return Ok(None);
|
||||
}
|
||||
let read = (end - at).min(u64::from(CHUNK)) as u32;
|
||||
let bytes = stream.read(at, read).await.map_err(io::Error::other)?;
|
||||
if bytes.is_empty() {
|
||||
return Err(io::Error::from(io::ErrorKind::UnexpectedEof));
|
||||
}
|
||||
let next = at + bytes.len() as u64;
|
||||
Ok(Some((Frame::data(Bytes::from(bytes)), (stream, next))))
|
||||
});
|
||||
response.body(BodyExt::boxed_unsync(StreamBody::new(body)))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::range;
|
||||
|
||||
#[test]
|
||||
fn resolves_seek_ranges_and_rejects_invalid_ranges() {
|
||||
assert_eq!(range(None, 10), Some((0, 10)));
|
||||
assert_eq!(range(Some("bytes=3-5"), 10), Some((3, 6)));
|
||||
assert_eq!(range(Some("bytes=9-"), 10), Some((9, 10)));
|
||||
assert_eq!(range(Some("bytes=-3"), 10), Some((7, 10)));
|
||||
assert_eq!(range(Some("bytes=10-"), 10), None);
|
||||
assert_eq!(range(Some("bytes=0-1,3-4"), 10), None);
|
||||
}
|
||||
}
|
||||
@@ -91,6 +91,7 @@ mod drive;
|
||||
use drive::{DriveApi, RevisionRead};
|
||||
mod events;
|
||||
mod filesystem;
|
||||
mod gallery;
|
||||
mod keeper;
|
||||
mod link;
|
||||
pub use filesystem::ProtonFs;
|
||||
@@ -499,6 +500,7 @@ struct Core {
|
||||
/// The concrete client, for what [`DriveApi`] does not cover: sharing,
|
||||
/// Photos, devices, invitations and public links.
|
||||
client: ProtonDriveClient,
|
||||
gallery: Option<Arc<gallery::Gallery>>,
|
||||
rt: tokio::runtime::Handle,
|
||||
/// The daemon's My Files root. Forked on-demand sessions retain this value
|
||||
/// so ownership checks never mistake their own mount root for account scope.
|
||||
@@ -4012,6 +4014,15 @@ impl Core {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn has_pending_moves_out_of(&self, uid: &NodeUid) -> Result<bool, Errno> {
|
||||
self.db
|
||||
.has_pending_moves_out_of(&uid.to_string())
|
||||
.map_err(|error| {
|
||||
error!(%uid, %error, "checking for moves out of a trash target failed");
|
||||
Errno::EIO
|
||||
})
|
||||
}
|
||||
|
||||
/// Queue trashing a node the server knows about, and drop it from the tree
|
||||
/// now.
|
||||
///
|
||||
@@ -5390,6 +5401,11 @@ impl Core {
|
||||
&parent_uid,
|
||||
)
|
||||
.map_err(|error| self.errno_error(error, "trash access"))?;
|
||||
if self.db.has_pending_moves_out_of(&uid.to_string())? {
|
||||
return Err(CoreError::conflict(
|
||||
"wait for pending moves out of this folder to sync before trashing it",
|
||||
));
|
||||
}
|
||||
self.rt
|
||||
.block_on(self.drive.trash_nodes(std::slice::from_ref(&uid)))
|
||||
.and_then(batch::into_unit)
|
||||
@@ -5454,11 +5470,13 @@ impl Core {
|
||||
} else {
|
||||
uid
|
||||
};
|
||||
// Local-first or offline, or the network goes away under the call:
|
||||
// queue the trash. The rename that follows queues as well, behind it.
|
||||
// Local-first or offline: queue the trash and the rename that follows.
|
||||
if !self.sends_inline() {
|
||||
return self.queue_trash(uid, name, open);
|
||||
}
|
||||
if self.has_pending_moves_out_of(uid)? {
|
||||
return Err(Errno::EBUSY);
|
||||
}
|
||||
self.require_uid_writable(uid)?;
|
||||
if let Err(e) = self
|
||||
.block_on_bounded(self.drive.trash_nodes(std::slice::from_ref(uid)))
|
||||
@@ -5754,7 +5772,7 @@ impl Core {
|
||||
/// Drop the persisted photos timeline's freshness stamp, so the next timeline
|
||||
/// read fetches rather than serving what it already has.
|
||||
fn invalidate_photos(&self) {
|
||||
let _ = self.db.clear_state(PHOTOS_SYNCED_MS);
|
||||
let _ = self.db.photos_invalidate();
|
||||
}
|
||||
|
||||
/// Drop one folder's cached child listing (`rel` is mountpoint-relative), so
|
||||
|
||||
@@ -232,6 +232,9 @@ impl Core {
|
||||
/// Unless the keyring holds a newer session than the refused one: then
|
||||
/// the mount ends, for the daemon to mount again on that one.
|
||||
pub(crate) fn mark_session_expired(&self, what: &str, error: &dyn std::fmt::Display) {
|
||||
if let Some(gallery) = &self.gallery {
|
||||
gallery.cancel();
|
||||
}
|
||||
if self.link.resume_stored.load(Ordering::Relaxed) {
|
||||
return self.mark_offline(what, error);
|
||||
}
|
||||
|
||||
@@ -310,6 +310,7 @@ enum Start {
|
||||
pub struct MountOptions {
|
||||
/// Proton account the session belongs to, for display and per-user paths.
|
||||
pub username: String,
|
||||
pub gallery_session: Option<proton_drive_rs::proton_sdk::session::ProtonApiSession>,
|
||||
/// What the background conflict sweep may do. See `docs/BUGS.md` B71.
|
||||
pub sweep_mode: SweepMode,
|
||||
/// Upload and download caps in bytes per second (`0` = no cap).
|
||||
@@ -456,6 +457,7 @@ pub(crate) fn mount_with(
|
||||
) -> std::io::Result<MountOutcome> {
|
||||
let MountOptions {
|
||||
username,
|
||||
gallery_session,
|
||||
sweep_mode,
|
||||
upload_limit,
|
||||
download_limit,
|
||||
@@ -480,9 +482,13 @@ pub(crate) fn mount_with(
|
||||
let (sync_tx, sync_rx) = std::sync::mpsc::channel::<sync::SyncMsg>();
|
||||
|
||||
let paused_until = pause::load_paused_until(&db);
|
||||
let gallery_dir = control_socket.with_file_name("gallery-catalog");
|
||||
let gallery =
|
||||
gallery_session.map(|session| Arc::new(super::gallery::Gallery::new(gallery_dir, session)));
|
||||
let core = Core {
|
||||
drive,
|
||||
client,
|
||||
gallery,
|
||||
rt: rt.clone(),
|
||||
maintenance: Arc::new(Mutex::new(Default::default())),
|
||||
primary_root_uid: root.uid.clone(),
|
||||
@@ -636,6 +642,9 @@ pub(crate) fn mount_with(
|
||||
// Keep the launcher prompt's "This computer" index fresh. Its own thread:
|
||||
// the walk is I/O-heavy and must never sit in front of a FUSE callback.
|
||||
if matches!(host, Host::Daemon) {
|
||||
if let Some(gallery) = &core.gallery {
|
||||
rt.spawn(gallery.clone().poll(core.clone()));
|
||||
}
|
||||
let db = core.db.clone();
|
||||
let indexing = core.indexing.clone();
|
||||
let transfers = core.transfers.clone();
|
||||
@@ -954,6 +963,9 @@ fn keep_or_abandon(
|
||||
/// Signal every worker to stop, then join them up to [`WORKER_JOIN_DEADLINE`].
|
||||
fn halt_workers(core: &Core, control_socket: &Path, workers: Vec<std::thread::JoinHandle<()>>) {
|
||||
core.shutdown.stop();
|
||||
if let Some(gallery) = &core.gallery {
|
||||
gallery.cancel();
|
||||
}
|
||||
core.wake_drain();
|
||||
let _ = core.sync_tx.send(sync::SyncMsg::Stop);
|
||||
// Connect while the socket still exists — that is the whole point of the
|
||||
|
||||
@@ -32,7 +32,7 @@ use tracing::{debug, info, warn};
|
||||
|
||||
use super::drive::RevisionRead;
|
||||
use super::{
|
||||
Core, PHOTOS_AVAILABLE, PHOTOS_SYNCED_MS, TIMELINE_ENRICH_CHUNK, TIMELINE_TTL, WriteAuthority,
|
||||
Core, PHOTOS_AVAILABLE, PHOTOS_SYNCED_MS, TIMELINE_ENRICH_CHUNK, WriteAuthority, link,
|
||||
node_size, now_ms, parse_uid,
|
||||
};
|
||||
|
||||
@@ -1144,18 +1144,6 @@ impl Drop for ProgressGuard<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
/// What a timeline enrichment pass resolves for one photo, beyond what the
|
||||
/// timeline listing already carries.
|
||||
#[derive(Clone, Debug)]
|
||||
struct PhotoMeta {
|
||||
name: Option<String>,
|
||||
media_type: Option<String>,
|
||||
favorite: bool,
|
||||
content_hash: Option<String>,
|
||||
/// Where the photo was taken, as its uploader recorded it.
|
||||
location: Option<(f64, f64)>,
|
||||
}
|
||||
|
||||
impl Core {
|
||||
/// [`upload_thumbnails`] for a file about to upload, staging any RAW copy
|
||||
/// under this cache. Blocking.
|
||||
@@ -1175,6 +1163,7 @@ impl Core {
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub(crate) fn photos_timeline(
|
||||
&self,
|
||||
offset: usize,
|
||||
@@ -1183,21 +1172,29 @@ impl Core {
|
||||
range: Option<(i64, i64)>,
|
||||
favorites: bool,
|
||||
not_in_album: bool,
|
||||
excluded: &str,
|
||||
) -> CoreResult<Option<Vec<PhotoItem>>> {
|
||||
let count = self.db.photos_count().map_err(CoreError::from)?;
|
||||
if count == 0 {
|
||||
// Nothing to serve, so this one request has to wait for the fetch —
|
||||
// unless we already know the account has no photos volume and the
|
||||
// answer is a fresh "no".
|
||||
let known_empty = self.db.state_i64(PHOTOS_AVAILABLE).ok().flatten() == Some(0);
|
||||
if known_empty && !self.listing_stale(PHOTOS_SYNCED_MS, TIMELINE_TTL) {
|
||||
return Ok(None);
|
||||
let listed = self
|
||||
.db
|
||||
.state_i64(PHOTOS_SYNCED_MS)
|
||||
.map_err(CoreError::from)?
|
||||
.is_some();
|
||||
if !listed {
|
||||
if count == 0 {
|
||||
if !self.refresh_timeline_joined()? {
|
||||
return Ok(None);
|
||||
}
|
||||
} else {
|
||||
self.spawn_timeline_refresh();
|
||||
}
|
||||
if !self.refresh_timeline_joined()? {
|
||||
return Ok(None);
|
||||
}
|
||||
} else if self.listing_stale(PHOTOS_SYNCED_MS, TIMELINE_TTL) {
|
||||
self.spawn_timeline_refresh();
|
||||
} else if self
|
||||
.db
|
||||
.state_i64(PHOTOS_AVAILABLE)
|
||||
.map_err(CoreError::from)?
|
||||
== Some(0)
|
||||
{
|
||||
return Ok(None);
|
||||
}
|
||||
// The filter is only as good as the album contents on disk, and those
|
||||
// are fetched lazily, per album opened. Fill in the missing ones before
|
||||
@@ -1208,7 +1205,15 @@ impl Core {
|
||||
|
||||
let page = self
|
||||
.db
|
||||
.photos_page(offset, limit, kind, range, favorites, not_in_album)
|
||||
.photos_page_visible(
|
||||
offset,
|
||||
limit,
|
||||
kind,
|
||||
range,
|
||||
favorites,
|
||||
not_in_album,
|
||||
excluded,
|
||||
)
|
||||
.map_err(CoreError::from)?;
|
||||
Ok(Some(page.into_iter().map(|p| self.photo_item(p)).collect()))
|
||||
}
|
||||
@@ -1365,8 +1370,11 @@ impl Core {
|
||||
/// The towns the photos were taken in, as wire items. A town the bundled
|
||||
/// table no longer knows (the stored id came from an older table) is left
|
||||
/// out rather than shown without a name.
|
||||
pub(crate) fn photo_places(&self) -> CoreResult<Vec<PlaceInfo>> {
|
||||
let places = self.db.photo_places().map_err(CoreError::from)?;
|
||||
pub(crate) fn photo_places(&self, excluded: &str) -> CoreResult<Vec<PlaceInfo>> {
|
||||
let places = self
|
||||
.db
|
||||
.photo_places_visible(excluded)
|
||||
.map_err(CoreError::from)?;
|
||||
Ok(places
|
||||
.into_iter()
|
||||
.filter_map(|place| {
|
||||
@@ -1390,10 +1398,11 @@ impl Core {
|
||||
id: u32,
|
||||
offset: usize,
|
||||
limit: usize,
|
||||
excluded: &str,
|
||||
) -> CoreResult<Vec<PhotoItem>> {
|
||||
let photos = self
|
||||
.db
|
||||
.photos_at_place(id, offset, limit)
|
||||
.photos_at_place_visible(id, offset, limit, excluded)
|
||||
.map_err(CoreError::from)?;
|
||||
Ok(photos.into_iter().map(|p| self.photo_item(p)).collect())
|
||||
}
|
||||
@@ -1417,13 +1426,17 @@ impl Core {
|
||||
/// Photos taken on today's date in earlier years, as wire items. Served
|
||||
/// from the stored timeline only: the strip is a nicety, not worth a wait
|
||||
/// on the network, and the timeline's own load keeps that store fresh.
|
||||
pub(crate) fn photos_on_this_day(&self, limit: usize) -> CoreResult<Vec<PhotoItem>> {
|
||||
pub(crate) fn photos_on_this_day(
|
||||
&self,
|
||||
limit: usize,
|
||||
excluded: &str,
|
||||
) -> CoreResult<Vec<PhotoItem>> {
|
||||
let now = std::time::SystemTime::now()
|
||||
.duration_since(std::time::UNIX_EPOCH)
|
||||
.map_or(0, |d| d.as_secs() as i64);
|
||||
let photos = self
|
||||
.db
|
||||
.photos_on_this_day(now, limit)
|
||||
.photos_on_this_day_visible(now, limit, excluded)
|
||||
.map_err(CoreError::from)?;
|
||||
Ok(photos.into_iter().map(|p| self.photo_item(p)).collect())
|
||||
}
|
||||
@@ -2477,162 +2490,113 @@ impl Core {
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether the listing stamped under `key` is older than `ttl` (or was never
|
||||
/// fetched).
|
||||
/// Commit the lightweight listing before resolving pending nodes. The
|
||||
/// feed generation fences both commits against events received in flight.
|
||||
pub(crate) async fn refresh_timeline(&self) -> CoreResult<bool> {
|
||||
let started = Instant::now();
|
||||
let generation = self
|
||||
.db
|
||||
.photo_projection_generation()
|
||||
.map_err(CoreError::from)?;
|
||||
let photos = self.photos();
|
||||
if photos
|
||||
.get_photos_root()
|
||||
.await
|
||||
.map_err(|e| CoreError::from_api(&e, "photos root"))?
|
||||
if self
|
||||
.db
|
||||
.state_i64(PHOTOS_SYNCED_MS)
|
||||
.map_err(CoreError::from)?
|
||||
.is_none()
|
||||
{
|
||||
let _ = self.db.set_state_i64(PHOTOS_AVAILABLE, 0);
|
||||
let _ = self.db.set_state_i64(PHOTOS_SYNCED_MS, now_ms());
|
||||
let available = link::bounded(photos.get_photos_root())
|
||||
.await
|
||||
.map_err(|e| CoreError::from_api(&e, "photos root"))?
|
||||
.is_some();
|
||||
let items = if available {
|
||||
link::bounded_by(super::BATCH_CALL_TIMEOUT, photos.enumerate_timeline())
|
||||
.await
|
||||
.map_err(|e| CoreError::from_api(&e, "timeline"))?
|
||||
.into_iter()
|
||||
.map(|item| db::TimelineRow::new(item.uid.to_string(), item.capture_time))
|
||||
.collect()
|
||||
} else {
|
||||
Vec::new()
|
||||
};
|
||||
if !self
|
||||
.db
|
||||
.photos_replace_at(&items, generation, available, now_ms())
|
||||
.map_err(CoreError::from)?
|
||||
{
|
||||
return Err(CoreError::remote(
|
||||
"Photos changed during the refresh. Try again shortly.",
|
||||
));
|
||||
}
|
||||
if !available {
|
||||
return Ok(false);
|
||||
}
|
||||
} else if self
|
||||
.db
|
||||
.state_i64(PHOTOS_AVAILABLE)
|
||||
.map_err(CoreError::from)?
|
||||
== Some(0)
|
||||
{
|
||||
return Ok(false);
|
||||
}
|
||||
let items = photos
|
||||
.enumerate_timeline()
|
||||
.await
|
||||
.map_err(|e| CoreError::from_api(&e, "timeline"))?;
|
||||
|
||||
// The timeline DTO carries only a uid and capture time, but the gallery
|
||||
// has to split into its tabs — which needs each photo's name and media
|
||||
// type. Resolve those in batches off the request path. Best-effort: a
|
||||
// photo whose node we fail to resolve keeps whatever was learned before
|
||||
// (or classifies from nothing, i.e. a still photo), so a partial resolve
|
||||
// never blanks the timeline.
|
||||
//
|
||||
// Only photos the daemon has never read, and ones a remote event marked
|
||||
// stale, are read. Resolving all of them every time is what made a
|
||||
// 12k-photo refresh take minutes (`docs/BUGS.md` B92): this metadata does
|
||||
// not change on its own, and when it does change the event feed names the
|
||||
// uid that changed (`Db::photos_mark_unresolved`).
|
||||
let known: HashSet<String> = self
|
||||
.db
|
||||
.photos_resolved()
|
||||
.map_err(CoreError::from)?
|
||||
.into_iter()
|
||||
.collect();
|
||||
let uids: Vec<NodeUid> = items
|
||||
.iter()
|
||||
.filter(|it| !known.contains(&it.uid.to_string()))
|
||||
.map(|it| it.uid.clone())
|
||||
.collect();
|
||||
let resolved_at = now_ms();
|
||||
let mut meta: HashMap<String, PhotoMeta> = HashMap::new();
|
||||
// A main photo names its related photos rather than the other way round,
|
||||
// so the relation is recorded from whichever end resolves — the two ends
|
||||
// can land in different chunks, and one of them may not resolve at all.
|
||||
let mut main_of: HashMap<String, String> = HashMap::new();
|
||||
let mut stopped = false;
|
||||
// Photos read before count as done, so the bar picks up where an
|
||||
// interrupted pass left off. Cleared however the pass ends.
|
||||
let skipped = items.len() - uids.len();
|
||||
let pending = self.db.photos_pending().map_err(CoreError::from)?;
|
||||
let total = self.db.photos_count().map_err(CoreError::from)?;
|
||||
let skipped = total.saturating_sub(pending.len());
|
||||
let mut resolved = 0;
|
||||
let progress = ProgressGuard(&self.timeline_progress);
|
||||
if !uids.is_empty() {
|
||||
*progress.0.lock() = Some((skipped, items.len()));
|
||||
}
|
||||
for (index, chunk) in uids.chunks(TIMELINE_ENRICH_CHUNK).enumerate() {
|
||||
// Teardown cancels the runtime under this loop, and every chunk
|
||||
// still in flight then fails its decrypt task — a burst of
|
||||
// "skipping undecryptable photo ... task was cancelled" warnings
|
||||
// that read like corruption and are only a shutdown. Stop asking
|
||||
// for chunks instead. What resolved so far is kept below; the rest
|
||||
// stay unresolved and are read by the next refresh.
|
||||
for (index, chunk) in pending.chunks(TIMELINE_ENRICH_CHUNK).enumerate() {
|
||||
if self.shutdown.is_stopping() {
|
||||
stopped = true;
|
||||
break;
|
||||
}
|
||||
match photos.enumerate_nodes(chunk).await {
|
||||
Ok(nodes) => {
|
||||
for node in nodes {
|
||||
let media_type = match &node.kind {
|
||||
NodeKind::File { media_type, .. } => Some(media_type.clone()),
|
||||
NodeKind::Folder => None,
|
||||
};
|
||||
// The favorite state is a tag on the photo node, so it
|
||||
// rides along with the metadata resolve rather than
|
||||
// costing a listing of its own.
|
||||
let favorite = node
|
||||
.photo
|
||||
.as_ref()
|
||||
.is_some_and(|p| p.tags.contains(&PhotoTag::Favorite));
|
||||
let key = node.uid.to_string();
|
||||
let content_hash = node.photo.as_ref().and_then(|p| p.content_hash.clone());
|
||||
let location = node
|
||||
.photo
|
||||
.as_ref()
|
||||
.and_then(|p| p.location)
|
||||
.map(|l| (l.latitude, l.longitude));
|
||||
if let Some(photo) = node.photo.as_ref() {
|
||||
if let Some(main) = photo.main_photo_uid.as_ref() {
|
||||
main_of.insert(key.clone(), main.to_string());
|
||||
}
|
||||
for related in &photo.related_photo_uids {
|
||||
main_of.insert(related.to_string(), key.clone());
|
||||
}
|
||||
}
|
||||
meta.insert(
|
||||
key,
|
||||
PhotoMeta {
|
||||
name: Some(node.name),
|
||||
media_type,
|
||||
favorite,
|
||||
content_hash,
|
||||
location,
|
||||
},
|
||||
);
|
||||
*progress.0.lock() = Some((skipped + index * TIMELINE_ENRICH_CHUNK, total));
|
||||
let uids: Vec<_> = chunk.iter().filter_map(|uid| parse_uid(uid)).collect();
|
||||
let nodes = link::bounded(photos.enumerate_nodes(&uids))
|
||||
.await
|
||||
.map_err(|e| CoreError::from_api(&e, "read photo metadata"))?;
|
||||
let rows: Vec<_> = nodes
|
||||
.into_iter()
|
||||
.filter_map(|node| {
|
||||
let NodeKind::File { media_type, .. } = node.kind else {
|
||||
return None;
|
||||
};
|
||||
if node.trashed {
|
||||
return None;
|
||||
}
|
||||
}
|
||||
Err(e) => warn!(error = %e, "resolving photo metadata for a timeline chunk failed"),
|
||||
let photo = node.photo.as_ref();
|
||||
Some(db::TimelineRow {
|
||||
name: Some(node.name),
|
||||
media_type: Some(media_type),
|
||||
favorite: Some(photo.is_some_and(|p| p.tags.contains(&PhotoTag::Favorite))),
|
||||
content_hash: photo.and_then(|p| p.content_hash.clone()),
|
||||
location: photo
|
||||
.and_then(|p| p.location)
|
||||
.map(|l| (l.latitude, l.longitude)),
|
||||
main_uid: photo
|
||||
.and_then(|p| p.main_photo_uid.as_ref())
|
||||
.map(ToString::to_string),
|
||||
resolved_at: Some(now_ms()),
|
||||
..db::TimelineRow::new(node.uid.to_string(), 0)
|
||||
})
|
||||
})
|
||||
.collect();
|
||||
if !self
|
||||
.db
|
||||
.photos_resolve_at(generation, &rows)
|
||||
.map_err(CoreError::from)?
|
||||
{
|
||||
return Err(CoreError::remote(
|
||||
"Photos changed during the refresh. Try again shortly.",
|
||||
));
|
||||
}
|
||||
let done = (skipped + (index + 1) * TIMELINE_ENRICH_CHUNK).min(items.len());
|
||||
*progress.0.lock() = Some((done, items.len()));
|
||||
resolved += rows.len();
|
||||
}
|
||||
drop(progress);
|
||||
|
||||
let rows: Vec<db::TimelineRow> = items
|
||||
.iter()
|
||||
.map(|it| {
|
||||
let key = it.uid.to_string();
|
||||
let main_uid = main_of.get(&key).cloned();
|
||||
// An unresolved photo keeps whatever was learned before, for the
|
||||
// favorite flag as much as for the name and media type.
|
||||
match meta.get(&key).cloned() {
|
||||
Some(m) => db::TimelineRow {
|
||||
name: m.name,
|
||||
media_type: m.media_type,
|
||||
favorite: Some(m.favorite),
|
||||
content_hash: m.content_hash,
|
||||
location: m.location,
|
||||
main_uid,
|
||||
resolved_at: Some(resolved_at),
|
||||
..db::TimelineRow::new(key, it.capture_time)
|
||||
},
|
||||
None => db::TimelineRow {
|
||||
main_uid,
|
||||
..db::TimelineRow::new(key, it.capture_time)
|
||||
},
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
self.db.photos_replace(&rows).map_err(CoreError::from)?;
|
||||
let _ = self.db.set_state_i64(PHOTOS_AVAILABLE, 1);
|
||||
let _ = self.db.set_state_i64(PHOTOS_SYNCED_MS, now_ms());
|
||||
// How long this took is the first thing to know when a refresh looks
|
||||
// like it never happened, and the chunk count is what it scales with.
|
||||
info!(
|
||||
photos = rows.len(),
|
||||
// `resolved` is what came back, which is short of `wanted` when
|
||||
// shutdown cut the pass off or a chunk failed.
|
||||
resolved = meta.len(),
|
||||
wanted = uids.len(),
|
||||
skipped = rows.len().saturating_sub(uids.len()),
|
||||
chunks = uids.len().div_ceil(TIMELINE_ENRICH_CHUNK),
|
||||
photos = total,
|
||||
resolved,
|
||||
wanted = pending.len(),
|
||||
skipped,
|
||||
elapsed_ms = started.elapsed().as_millis() as u64,
|
||||
stopped,
|
||||
"photos timeline refreshed"
|
||||
);
|
||||
Ok(true)
|
||||
@@ -2656,7 +2620,11 @@ impl Core {
|
||||
// A refresh that landed stamped the timeline fresh. One that failed
|
||||
// did not, and the caller gets this refresh's own error instead of
|
||||
// an empty timeline.
|
||||
if !self.listing_stale(PHOTOS_SYNCED_MS, TIMELINE_TTL)
|
||||
if self
|
||||
.db
|
||||
.state_i64(PHOTOS_SYNCED_MS)
|
||||
.map_err(CoreError::from)?
|
||||
.is_some()
|
||||
|| self.timeline_refreshing.swap(true, Ordering::SeqCst)
|
||||
{
|
||||
return Ok(self.db.state_i64(PHOTOS_AVAILABLE).ok().flatten() != Some(0));
|
||||
|
||||
@@ -89,6 +89,7 @@ impl Daemon {
|
||||
db,
|
||||
MountOptions {
|
||||
username: "sim".into(),
|
||||
gallery_session: None,
|
||||
sweep_mode: AppConfig::default().resolved_conflict_sweep(),
|
||||
upload_limit: 0,
|
||||
download_limit: 0,
|
||||
@@ -1917,6 +1918,68 @@ mod tests {
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "mounts FUSE: run with `cargo test -p pdfs-fuse sim:: -- --ignored`"]
|
||||
fn a_move_blocked_by_trash_can_be_retried_after_restore() {
|
||||
use pdfs_core::control::SyncIssue;
|
||||
|
||||
let drive = FakeDrive::new();
|
||||
let dir = scratch("move-out-of-trash");
|
||||
let daemon = Daemon::start(&dir, drive.client(1, Faults::none())).unwrap();
|
||||
let mount = &daemon.mountpoint;
|
||||
std::fs::create_dir_all(mount.join("source/nested")).unwrap();
|
||||
std::fs::create_dir(mount.join("destination")).unwrap();
|
||||
std::fs::write(mount.join("source/nested/wallpaper.jpg"), b"image").unwrap();
|
||||
assert!(wait_until(Duration::from_secs(30), || daemon.drained()
|
||||
&& drive.lookup("source/nested/wallpaper.jpg").is_some()));
|
||||
let source = drive.lookup("source").unwrap();
|
||||
|
||||
let pause = |paused| Request::SetSyncPaused {
|
||||
paused,
|
||||
until: None,
|
||||
};
|
||||
daemon.request(&pause(true)).unwrap();
|
||||
std::fs::rename(
|
||||
mount.join("source/nested/wallpaper.jpg"),
|
||||
mount.join("destination/wallpaper.jpg"),
|
||||
)
|
||||
.unwrap();
|
||||
drive.device().trash("source");
|
||||
daemon.request(&pause(false)).unwrap();
|
||||
assert!(wait_until(Duration::from_secs(30), || daemon
|
||||
.pending()
|
||||
.is_ok_and(|ops| ops.iter().any(|op| op.issue
|
||||
== Some(SyncIssue::Trashed)
|
||||
&& op
|
||||
.last_error
|
||||
.as_deref()
|
||||
.is_some_and(|message| message.contains("‘source’"))))));
|
||||
|
||||
daemon
|
||||
.request(&Request::RetryPendingOp { id: None })
|
||||
.unwrap();
|
||||
assert!(wait_until(Duration::from_secs(30), || daemon
|
||||
.pending()
|
||||
.is_ok_and(|ops| ops.iter().any(|op| op.attempts >= 2))));
|
||||
daemon
|
||||
.request(&Request::Restore {
|
||||
uids: vec![source.to_string()],
|
||||
})
|
||||
.unwrap();
|
||||
daemon
|
||||
.request(&Request::RetryPendingOp { id: None })
|
||||
.unwrap();
|
||||
assert!(wait_until(Duration::from_secs(30), || daemon.drained()
|
||||
&& drive.lookup("destination/wallpaper.jpg").is_some()));
|
||||
assert_eq!(
|
||||
std::fs::read(mount.join("destination/wallpaper.jpg")).unwrap(),
|
||||
b"image"
|
||||
);
|
||||
|
||||
assert!(matches!(daemon.stop(), Ok(MountOutcome::Shutdown)));
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "mounts FUSE: run with `cargo test -p pdfs-fuse sim:: -- --ignored`"]
|
||||
fn a_write_over_a_create_whose_read_back_failed_is_not_a_conflict() {
|
||||
|
||||
@@ -160,6 +160,17 @@ impl Server {
|
||||
.is_some_and(|remote| remote.file.is_none() && !remote.trashed)
|
||||
}
|
||||
|
||||
fn in_trash(&self, uid: &NodeUid) -> bool {
|
||||
let mut node = self.current(uid);
|
||||
while let Some(remote) = node {
|
||||
if remote.trashed {
|
||||
return true;
|
||||
}
|
||||
node = remote.parent.as_ref().and_then(|uid| self.current(uid));
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
fn is_below(&self, uid: &NodeUid, ancestor: &NodeUid) -> bool {
|
||||
let mut cursor = Some(uid.clone());
|
||||
while let Some(at) = cursor {
|
||||
@@ -1037,6 +1048,12 @@ impl FakeClient {
|
||||
}
|
||||
let parent = new_parent.cloned().or(remote.parent.clone());
|
||||
let name = new_name.unwrap_or(&remote.name).to_owned();
|
||||
if server.in_trash(uid) || parent.as_ref().is_some_and(|uid| server.in_trash(uid)) {
|
||||
return Err(api(
|
||||
ResponseCode::NotEnoughPermissions,
|
||||
"an item involved in the move is in Trash",
|
||||
));
|
||||
}
|
||||
if let Some(parent) = &parent {
|
||||
if !server.is_folder(parent) {
|
||||
return Err(api(
|
||||
|
||||
@@ -112,6 +112,8 @@ struct Run {
|
||||
/// Run `profile` on `seed`. It answers a report of what went wrong, if
|
||||
/// anything did.
|
||||
pub(crate) fn run(seed: u64, profile: &'static Profile) -> Result<(), String> {
|
||||
// The simulation suite runs serially. Discard logs left by earlier tests.
|
||||
take_logged();
|
||||
let dir = scratch(&format!("{}-{seed}", profile.name));
|
||||
let mut rng = Rng::new(seed);
|
||||
let drive = FakeDrive::new();
|
||||
@@ -137,6 +139,7 @@ pub(crate) fn run(seed: u64, profile: &'static Profile) -> Result<(), String> {
|
||||
let _ = daemon.stop();
|
||||
}
|
||||
}
|
||||
run.logged.extend(take_logged());
|
||||
match outcome {
|
||||
Ok(()) => {
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
@@ -432,6 +435,7 @@ impl Run {
|
||||
|
||||
fn report(&self, failure: &str, dir: &Path) -> String {
|
||||
let _ = std::fs::write(dir.join("steps.log"), self.log.join("\n") + "\n");
|
||||
let _ = std::fs::write(dir.join("daemon.log"), self.logged.join("\n") + "\n");
|
||||
let tail = &self.log[self.log.len().saturating_sub(LOG_TAIL)..];
|
||||
format!(
|
||||
"{} seed {} failed: {failure}\nreplay with PDFS_SIM_SEED={}; state kept in {}\nlast steps:\n{}",
|
||||
|
||||
@@ -527,7 +527,7 @@ impl Core {
|
||||
let scan = match scan_archives_until(archives, || self.import_should_stop(cancel)) {
|
||||
Ok(scan) => scan,
|
||||
Err(_) if self.import_should_stop(cancel) => return Ok(true),
|
||||
Err(e) => return Err(e),
|
||||
Err(e) => return Err(CoreError::conflict(e.to_string())),
|
||||
};
|
||||
*planned = plan(&scan);
|
||||
*albums = scan.albums.clone();
|
||||
|
||||
@@ -22,6 +22,8 @@ name = "pdfs-prompt"
|
||||
path = "src/prompt.rs"
|
||||
|
||||
[dependencies]
|
||||
proton-gallery-rs.workspace = true
|
||||
base64.workspace = true
|
||||
pdfs-core.workspace = true
|
||||
tracing.workspace = true
|
||||
tracing-subscriber.workspace = true
|
||||
|
||||
@@ -118,11 +118,15 @@ scale.browser-status-meter trough { min-width: 140px; min-height: 6px; }
|
||||
.memory-card { padding: 0; border-radius: 12px; }
|
||||
.memory-cover { border-radius: 12px; background: alpha(currentColor, 0.06); }
|
||||
.memory-label { font-weight: 700; color: white; text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9); padding: 22px 10px 6px 10px; background: linear-gradient(to top, rgba(0, 0, 0, 0.6), rgba(0, 0, 0, 0)); }
|
||||
/* The button handles hover and clicks. The FlowBox cell can be wider than it. */
|
||||
flowbox.photo-album-grid > flowboxchild:hover,
|
||||
flowbox.photo-album-grid > flowboxchild:active { background: transparent; }
|
||||
.album-card { padding: 0; border-radius: 16px; transition: background 180ms ease; }
|
||||
.album-card:hover { background: alpha(currentColor, 0.07); }
|
||||
.album-cover { border-radius: 16px; background: alpha(currentColor, 0.06); box-shadow: 0 4px 16px rgba(0, 0, 0, 0.32); transition: box-shadow 180ms ease; }
|
||||
.album-card:hover .album-cover { box-shadow: 0 10px 26px rgba(0, 0, 0, 0.5); }
|
||||
.album-card:hover .photo-thumb { transform: scale(1.05); }
|
||||
listview.drive-gallery-rows > row { padding: 0; }
|
||||
.view-switch button, .view-switch toggle { padding-left: 12px; padding-right: 12px; }
|
||||
|
||||
/* Shared with Me: what a share lets me do, as a tinted pill beside the name. */
|
||||
|
||||
@@ -100,6 +100,9 @@ fn on_feed(ui: &Rc<Ui>, state: &Rc<FeedState>, feed: Feed, hidden: bool) {
|
||||
follow_takeout(ui, state, &jobs);
|
||||
}
|
||||
Feed::Event(Event::Changed { topics }) if hidden => {
|
||||
if topics.contains(&Topic::Photos) {
|
||||
check_photo_viewer(ui);
|
||||
}
|
||||
state.deferred.borrow_mut().extend(topics);
|
||||
}
|
||||
Feed::Event(Event::Changed { topics }) => follow_changes(ui, state, &topics),
|
||||
@@ -133,10 +136,45 @@ fn follow_changes(ui: &Rc<Ui>, state: &FeedState, topics: &[Topic]) {
|
||||
refresh_file_thumbnails(ui);
|
||||
}
|
||||
let page = ui.stack.visible_child_name();
|
||||
// A timeline out of sight is read again when the user comes back to it;
|
||||
// one on screen is left alone (below).
|
||||
if changed(Topic::Photos) && (page.as_deref() != Some("gallery") || !photo_grid_shown(ui)) {
|
||||
if changed(Topic::GalleryVisibility) || changed(Topic::GalleryVisibilitySynced) {
|
||||
if let Some(browser) = ui.drive_galleries.borrow().upgrade() {
|
||||
browser.refresh_visibility(changed(Topic::GalleryVisibility));
|
||||
}
|
||||
for window in gtk4::Window::list_toplevels() {
|
||||
if let Ok(window) = window.downcast::<gtk4::Window>()
|
||||
&& window.has_css_class("photo-viewer-window")
|
||||
{
|
||||
window.close();
|
||||
}
|
||||
}
|
||||
ui.gallery
|
||||
.thumb_generation
|
||||
.set(ui.gallery.thumb_generation.get().wrapping_add(1));
|
||||
ui.gallery.thumb_queue.borrow_mut().clear();
|
||||
ui.gallery.decode_queue.borrow_mut().clear();
|
||||
ui.gallery.thumb_wanted.borrow_mut().clear();
|
||||
ui.gallery.photo_tex.borrow_mut().clear();
|
||||
ui.gallery.photo_tex_order.borrow_mut().clear();
|
||||
ui.gallery.model.remove_all();
|
||||
ui.gallery.groups.remove_all();
|
||||
ui.gallery.row_by_photo.borrow_mut().clear();
|
||||
ui.gallery.timeline_stale.set(true);
|
||||
if page.as_deref() == Some("gallery") {
|
||||
match ui.gallery.content.visible_child_name().as_deref() {
|
||||
Some("albums") => load_albums(ui),
|
||||
Some("drive-galleries") => {}
|
||||
Some("places") => load_places(ui),
|
||||
_ => load_gallery(ui, false),
|
||||
}
|
||||
}
|
||||
}
|
||||
if changed(Topic::Photos) {
|
||||
check_photo_viewer(ui);
|
||||
if page.as_deref() != Some("gallery") || !photo_grid_shown(ui) {
|
||||
ui.gallery.timeline_stale.set(true);
|
||||
} else {
|
||||
refresh_visible_photos(ui);
|
||||
}
|
||||
}
|
||||
match page.as_deref() {
|
||||
// A search on screen is left alone: reloading would swap its hits for
|
||||
@@ -144,8 +182,6 @@ fn follow_changes(ui: &Rc<Ui>, state: &FeedState, topics: &[Topic]) {
|
||||
Some("browser") if changed(Topic::Files) && ui.browser.search.text().trim().is_empty() => {
|
||||
load_browser(ui)
|
||||
}
|
||||
// The timeline is left alone: reloading it would throw away the place
|
||||
// the user scrolled to. F5 reloads it on request.
|
||||
Some("gallery")
|
||||
if changed(Topic::Photos)
|
||||
&& ui.gallery.content.visible_child_name().as_deref() == Some("albums") =>
|
||||
|
||||
@@ -26,9 +26,12 @@ use pages::photo_viewer::*;
|
||||
use pages::photos::*;
|
||||
use pages::places::*;
|
||||
use pages::places_map::*;
|
||||
use pages::preferences_apps::*;
|
||||
use pages::preferences_sync::*;
|
||||
use pages::shared::*;
|
||||
use pages::shared_by_me::*;
|
||||
use pages::status::*;
|
||||
use pages::sync_exclusions::*;
|
||||
use pages::takeout::*;
|
||||
use pages::trash::*;
|
||||
use pages::verify::*;
|
||||
@@ -39,6 +42,7 @@ use widgets::compat::*;
|
||||
use widgets::crumb::*;
|
||||
use widgets::details::*;
|
||||
use widgets::file_list::*;
|
||||
use widgets::ignore_dialog::*;
|
||||
use widgets::menu::*;
|
||||
use widgets::photo_drag::*;
|
||||
use widgets::player::*;
|
||||
@@ -156,6 +160,7 @@ struct Ui {
|
||||
pub(crate) details: DetailsState,
|
||||
pub(crate) trash: TrashState,
|
||||
pub(crate) gallery: GalleryState,
|
||||
drive_galleries: RefCell<std::rc::Weak<pages::drive_galleries::Browser>>,
|
||||
pub(crate) shared: SharedState,
|
||||
pub(crate) shared_by_me: SharedByMeState,
|
||||
pub(crate) devices: DevicesState,
|
||||
@@ -307,6 +312,18 @@ fn sync_view(page: &str) -> Option<&'static str> {
|
||||
}
|
||||
}
|
||||
|
||||
/// The Preferences page a `--page` name opens: "preferences" and
|
||||
/// "preferences-" followed by the page's name.
|
||||
fn preferences_page(page: &str) -> Option<&'static str> {
|
||||
match page {
|
||||
"preferences" | "preferences-general" => Some("general"),
|
||||
"preferences-sync" => Some("sync"),
|
||||
"preferences-apps" => Some("apps"),
|
||||
"preferences-storage" => Some("storage"),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// The Photos view a `--page` name opens, and whether Places shows its map:
|
||||
/// "albums", "places" and "places-map". Other names are stack pages.
|
||||
fn photos_view(page: &str) -> Option<(u32, bool)> {
|
||||
@@ -329,7 +346,15 @@ fn present_window(app: &adw::Application) {
|
||||
|
||||
/// Spawn the tray icon process in the background.
|
||||
pub(crate) fn spawn_tray() {
|
||||
match Command::new("pdfs-tray").spawn() {
|
||||
// The tray installed next to this app, as the tray finds the app; the
|
||||
// bare name for a PATH install. An install into ~/.local is often not on
|
||||
// the PATH of a desktop session.
|
||||
let tray = std::env::current_exe()
|
||||
.ok()
|
||||
.and_then(|p| p.parent().map(|d| d.join("pdfs-tray")))
|
||||
.filter(|p| p.exists())
|
||||
.unwrap_or_else(|| PathBuf::from("pdfs-tray"));
|
||||
match Command::new(&tray).spawn() {
|
||||
Ok(child) => {
|
||||
tracing::info!("spawned `pdfs-tray`");
|
||||
pdfs_core::opener::reap(child);
|
||||
@@ -435,6 +460,7 @@ fn build_window(app: &adw::Application) {
|
||||
nav: split.clone(),
|
||||
narrow: Cell::new(false),
|
||||
file_thumbs: FileThumbnailState::new(),
|
||||
drive_galleries: RefCell::default(),
|
||||
login: login_widgets,
|
||||
status: StatusState {
|
||||
status_inflight: Cell::new(false),
|
||||
@@ -535,6 +561,10 @@ fn build_window(app: &adw::Application) {
|
||||
gallery: GalleryState {
|
||||
model: gallery_widgets.model.clone(),
|
||||
groups: gallery_widgets.groups.clone(),
|
||||
row_by_photo: RefCell::default(),
|
||||
rendered_layout: Cell::new(None),
|
||||
rendered_photos: Cell::new(0),
|
||||
align_tick: RefCell::default(),
|
||||
row_height: Cell::new(ROW_DEFAULT),
|
||||
scrolling_down: Cell::new(true),
|
||||
scroll_offset: Cell::new(0.0),
|
||||
@@ -591,6 +621,10 @@ fn build_window(app: &adw::Application) {
|
||||
memory_cards: gallery_widgets.memory_cards.clone(),
|
||||
has_memories: Cell::new(false),
|
||||
date_suppress: Cell::new(false),
|
||||
months_loading: Cell::new(false),
|
||||
months_pending: Cell::new(false),
|
||||
changes_pending: Cell::new(false),
|
||||
viewer: RefCell::new(std::rc::Weak::new()),
|
||||
reload_pending: Cell::new(false),
|
||||
loading: Cell::new(false),
|
||||
has_more: Cell::new(false),
|
||||
@@ -602,12 +636,14 @@ fn build_window(app: &adw::Application) {
|
||||
photo_nothumb: RefCell::new(HashSet::new()),
|
||||
thumb_wanted: RefCell::new(HashMap::new()),
|
||||
thumb_queue: RefCell::new(VecDeque::new()),
|
||||
thumb_inflight: Cell::new(false),
|
||||
thumb_inflight: RefCell::default(),
|
||||
thumb_generation: Cell::new(0),
|
||||
decode_queue: RefCell::new(VecDeque::new()),
|
||||
decode_idle: Cell::new(false),
|
||||
thumb_source: RefCell::new(None),
|
||||
relayout_source: RefCell::new(None),
|
||||
bound: RefCell::new(BTreeMap::new()),
|
||||
visible_tiles_pending: Cell::new(0),
|
||||
tile_pools: RefCell::new(HashMap::new()),
|
||||
list: gallery_widgets.list.clone(),
|
||||
selecting: Cell::new(false),
|
||||
@@ -658,6 +694,13 @@ fn build_window(app: &adw::Application) {
|
||||
views: locations_widgets.views.clone(),
|
||||
banner: locations_widgets.banner.clone(),
|
||||
failing: Cell::new(0),
|
||||
exclusions: ExclusionsState {
|
||||
group: locations_widgets.exclusions_group.clone(),
|
||||
add: locations_widgets.add_pattern.clone(),
|
||||
rows: RefCell::new(Vec::new()),
|
||||
folders: RefCell::new(Vec::new()),
|
||||
generation: Cell::new(0),
|
||||
},
|
||||
},
|
||||
activity: ActivityState {
|
||||
content: activity_widgets.content.clone(),
|
||||
@@ -710,6 +753,8 @@ fn build_window(app: &adw::Application) {
|
||||
&main_widgets.purge_button,
|
||||
&main_widgets.mountpoint_button,
|
||||
);
|
||||
wire_sync_prefs(&ui, main_widgets.sync_prefs);
|
||||
wire_apps_prefs(&ui, main_widgets.apps_prefs);
|
||||
wire_sidebar(&ui);
|
||||
wire_browser(&ui);
|
||||
wire_bulk(
|
||||
@@ -739,6 +784,7 @@ fn build_window(app: &adw::Application) {
|
||||
wire_shared_by_me(&ui, &shared_by_me_widgets);
|
||||
wire_devices(&ui, &devices_widgets);
|
||||
wire_locations(&ui, &locations_widgets.retry, &locations_widgets.add_folder);
|
||||
wire_exclusions(&ui);
|
||||
wire_activity(&ui, &activity_widgets);
|
||||
wire_takeout(&ui, &takeout_widgets);
|
||||
wire_retry(&ui);
|
||||
@@ -753,6 +799,11 @@ fn build_window(app: &adw::Application) {
|
||||
// thumbnail generation as it paints.
|
||||
cancel_file_thumbnails(&ui_nav);
|
||||
sync_sidebar(&ui_nav);
|
||||
if st.visible_child_name().as_deref() != Some("gallery")
|
||||
&& let Some(browser) = ui_nav.drive_galleries.borrow().upgrade()
|
||||
{
|
||||
browser.close();
|
||||
}
|
||||
match st.visible_child_name().as_deref() {
|
||||
Some("browser") => reload_browser_view(&ui_nav),
|
||||
// The Albums and Places listings are re-read in place. Loading the
|
||||
@@ -762,7 +813,7 @@ fn build_window(app: &adw::Application) {
|
||||
// sight (see `follow_changes`) or nothing is loaded yet.
|
||||
Some("gallery") if !ui_nav.gallery.in_collection() => {
|
||||
match ui_nav.gallery.view_switch.active() {
|
||||
VIEW_ALBUMS => load_albums(&ui_nav),
|
||||
VIEW_ALBUMS => show_albums(&ui_nav),
|
||||
VIEW_PLACES => load_places(&ui_nav),
|
||||
_ if ui_nav.gallery.timeline_stale.replace(false)
|
||||
|| ui_nav.gallery.model.n_items() == 0 =>
|
||||
@@ -799,6 +850,14 @@ fn build_window(app: &adw::Application) {
|
||||
.height_request(WindowState::MIN_HEIGHT)
|
||||
.content(&toasts)
|
||||
.build();
|
||||
pages::drive_galleries::wire(
|
||||
&ui,
|
||||
&window,
|
||||
&gallery_widgets.drive_galleries,
|
||||
&gallery_widgets.drive_status,
|
||||
&gallery_widgets.add_gallery,
|
||||
&gallery_widgets.hidden_albums,
|
||||
);
|
||||
remember_window_state(&ui, app, &window);
|
||||
// A wide window docks the details pane beside the files instead of laying it
|
||||
// over them.
|
||||
@@ -868,12 +927,10 @@ fn save_window_state(ui: &Ui, window: &adw::ApplicationWindow) {
|
||||
height,
|
||||
maximized: window.is_maximized(),
|
||||
};
|
||||
let mut config = ui.dirs.load_config();
|
||||
if config.window == state {
|
||||
if ui.dirs.load_config().window == state {
|
||||
return;
|
||||
}
|
||||
config.window = state;
|
||||
if let Err(e) = ui.dirs.save_config(&config) {
|
||||
if let Err(e) = ui.dirs.update_config(|config| config.window = state) {
|
||||
tracing::warn!("cannot save the window size: {e}");
|
||||
}
|
||||
}
|
||||
@@ -1471,7 +1528,10 @@ fn install_launch_actions(ui: &Rc<Ui>, app: &adw::Application, window: &adw::App
|
||||
show_login(&ui_page);
|
||||
return;
|
||||
}
|
||||
if let Some(view) = sync_view(page) {
|
||||
if let Some(name) = preferences_page(page) {
|
||||
ui_page.status.prefs.set_visible_page_name(name);
|
||||
ui_page.status.prefs.present(ui_window(&ui_page).as_ref());
|
||||
} else if let Some(view) = sync_view(page) {
|
||||
ui_page.locations.views.set_visible_child_name(view);
|
||||
ui_page.stack.set_visible_child_name("locations");
|
||||
} else if let Some((view, map)) = photos_view(page) {
|
||||
@@ -1638,7 +1698,9 @@ fn install_shortcuts(ui: &Rc<Ui>, window: &adw::ApplicationWindow) {
|
||||
let on_trash = page.as_deref() == Some("trash");
|
||||
let on_gallery = page.as_deref() == Some("gallery");
|
||||
// Pages with a level to go back to, besides My files' own history.
|
||||
let in_collection = on_gallery && ui.gallery.in_collection();
|
||||
let in_collection = on_gallery
|
||||
&& (ui.gallery.in_collection()
|
||||
|| ui.gallery.content.visible_child_name().as_deref() == Some("drive-galleries"));
|
||||
let in_shared_folder =
|
||||
page.as_deref() == Some("shared") && !ui.shared.nav.borrow().is_empty();
|
||||
let in_device_folder =
|
||||
@@ -2055,6 +2117,15 @@ mod tests {
|
||||
assert_eq!(sync_view("locations"), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_page_name_can_open_a_preferences_page() {
|
||||
assert_eq!(preferences_page("preferences"), Some("general"));
|
||||
assert_eq!(preferences_page("preferences-sync"), Some("sync"));
|
||||
assert_eq!(preferences_page("preferences-apps"), Some("apps"));
|
||||
assert_eq!(preferences_page("preferences-storage"), Some("storage"));
|
||||
assert_eq!(preferences_page("sync"), None);
|
||||
}
|
||||
|
||||
/// One file of a shot, for the group-switch tests.
|
||||
fn member(uid: &str, name: Option<&str>, kind: PhotoKind) -> PhotoItem {
|
||||
PhotoItem {
|
||||
|
||||
@@ -18,6 +18,9 @@ const COVER_EDGE: i32 = 200;
|
||||
pub(crate) fn show_albums(ui: &Rc<Ui>) {
|
||||
show_album_grid(ui);
|
||||
load_albums(ui);
|
||||
if let Some(browser) = ui.drive_galleries.borrow().upgrade() {
|
||||
browser.load_root();
|
||||
}
|
||||
}
|
||||
|
||||
/// Switch to the album grid as it was last filled, keeping its scroll
|
||||
@@ -102,7 +105,7 @@ fn fill_albums(ui: &Rc<Ui>, albums: &[AlbumInfo]) {
|
||||
ui.gallery.albums.remove(&child);
|
||||
}
|
||||
*ui.gallery.album_list.borrow_mut() = albums.to_vec();
|
||||
if ui.gallery.album.borrow().is_none() {
|
||||
if ui.gallery.content.visible_child_name().as_deref() == Some("albums") {
|
||||
ui.gallery.title.set_subtitle(&ngettext_f(
|
||||
"{n} album",
|
||||
"{n} albums",
|
||||
@@ -125,7 +128,12 @@ fn fill_albums(ui: &Rc<Ui>, albums: &[AlbumInfo]) {
|
||||
/// One album as a clickable card: its cover, its name, and how many photos it
|
||||
/// holds. An album shared with us says so — it lives on someone else's volume,
|
||||
/// and that is worth knowing before opening it.
|
||||
fn album_card(ui: &Rc<Ui>, album: &AlbumInfo) -> gtk4::Button {
|
||||
pub(crate) fn collection_card(
|
||||
title: &str,
|
||||
subtitle: &str,
|
||||
icon: &str,
|
||||
(width, height): (i32, i32),
|
||||
) -> (gtk4::Button, gtk4::Picture) {
|
||||
let picture = gtk4::Picture::builder()
|
||||
// Fills and crops the cover square, like a timeline tile.
|
||||
.content_fit(gtk4::ContentFit::Cover)
|
||||
@@ -136,7 +144,7 @@ fn album_card(ui: &Rc<Ui>, album: &AlbumInfo) -> gtk4::Button {
|
||||
picture.add_css_class("photo-thumb");
|
||||
|
||||
let placeholder = gtk4::Image::builder()
|
||||
.icon_name("pdfs-album-symbolic")
|
||||
.icon_name(icon)
|
||||
.pixel_size(32)
|
||||
.halign(gtk4::Align::Center)
|
||||
.valign(gtk4::Align::Center)
|
||||
@@ -146,12 +154,12 @@ fn album_card(ui: &Rc<Ui>, album: &AlbumInfo) -> gtk4::Button {
|
||||
let cover = gtk4::Overlay::new();
|
||||
cover.set_child(Some(&placeholder));
|
||||
cover.add_overlay(&picture);
|
||||
cover.set_size_request(COVER_EDGE, COVER_EDGE);
|
||||
cover.set_size_request(width, height);
|
||||
cover.set_overflow(gtk4::Overflow::Hidden);
|
||||
cover.add_css_class("album-cover");
|
||||
|
||||
let name = gtk4::Label::builder()
|
||||
.label(&album.name)
|
||||
.label(title)
|
||||
.halign(gtk4::Align::Start)
|
||||
.xalign(0.0)
|
||||
.ellipsize(gtk4::pango::EllipsizeMode::End)
|
||||
@@ -159,7 +167,7 @@ fn album_card(ui: &Rc<Ui>, album: &AlbumInfo) -> gtk4::Button {
|
||||
name.add_css_class("heading");
|
||||
|
||||
let count = gtk4::Label::builder()
|
||||
.label(album_subtitle(album))
|
||||
.label(subtitle)
|
||||
.halign(gtk4::Align::Start)
|
||||
.xalign(0.0)
|
||||
.ellipsize(gtk4::pango::EllipsizeMode::End)
|
||||
@@ -172,10 +180,23 @@ fn album_card(ui: &Rc<Ui>, album: &AlbumInfo) -> gtk4::Button {
|
||||
card.append(&name);
|
||||
card.append(&count);
|
||||
|
||||
let button = gtk4::Button::builder().child(&card).build();
|
||||
let button = gtk4::Button::builder()
|
||||
.child(&card)
|
||||
.halign(gtk4::Align::Start)
|
||||
.build();
|
||||
button.add_css_class("flat");
|
||||
button.add_css_class("album-card");
|
||||
button.set_tooltip_text(Some(&album.name));
|
||||
button.set_tooltip_text(Some(title));
|
||||
(button, picture)
|
||||
}
|
||||
|
||||
fn album_card(ui: &Rc<Ui>, album: &AlbumInfo) -> gtk4::Button {
|
||||
let (button, picture) = collection_card(
|
||||
&album.name,
|
||||
&album_subtitle(album),
|
||||
"pdfs-album-symbolic",
|
||||
(COVER_EDGE, COVER_EDGE),
|
||||
);
|
||||
|
||||
if let Some(uid) = album.cover_uid.clone() {
|
||||
want_cover(ui, uid, &picture);
|
||||
@@ -693,6 +714,12 @@ pub(crate) fn wire_albums(ui: &Rc<Ui>) {
|
||||
// where it was, instead of reloading it.
|
||||
let ui_back = ui.clone();
|
||||
ui.gallery.back.clone().connect_clicked(move |_| {
|
||||
if ui_back.gallery.content.visible_child_name().as_deref() == Some("drive-galleries") {
|
||||
if let Some(browser) = ui_back.drive_galleries.borrow().upgrade() {
|
||||
browser.back();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if ui_back.gallery.place.borrow().is_some() {
|
||||
show_place_grid(&ui_back);
|
||||
return;
|
||||
|
||||
@@ -1431,9 +1431,11 @@ fn save_icon_size(ui: &Rc<Ui>, size: i32) {
|
||||
let ui_save = ui.clone();
|
||||
let source = glib::timeout_add_local_once(Duration::from_millis(500), move || {
|
||||
ui_save.browser.zoom_save.borrow_mut().take();
|
||||
let mut config = ui_save.dirs.load_config();
|
||||
config.files_view.icon_size = ui_save.browser.view.get().icon_size;
|
||||
if let Err(e) = ui_save.dirs.save_config(&config) {
|
||||
let icon_size = ui_save.browser.view.get().icon_size;
|
||||
if let Err(e) = ui_save
|
||||
.dirs
|
||||
.update_config(|config| config.files_view.icon_size = icon_size)
|
||||
{
|
||||
tracing::warn!("cannot save the icon size: {e}");
|
||||
}
|
||||
});
|
||||
@@ -1464,9 +1466,7 @@ pub(crate) fn set_files_view(ui: &Rc<Ui>, view: FilesView) {
|
||||
return;
|
||||
}
|
||||
apply_files_view(ui, view);
|
||||
let mut config = ui.dirs.load_config();
|
||||
config.files_view = view;
|
||||
if let Err(e) = ui.dirs.save_config(&config) {
|
||||
if let Err(e) = ui.dirs.update_config(|config| config.files_view = view) {
|
||||
toast_error(ui, &gettext("Couldn't save the view"), &e.to_string());
|
||||
}
|
||||
if (old.sort, old.descending, old.folders_first)
|
||||
|
||||
@@ -35,6 +35,8 @@ pub(crate) struct LocationsState {
|
||||
pub(crate) banner: adw::Banner,
|
||||
/// Changes the daemon failed to upload, from the last status.
|
||||
pub(crate) failing: Cell<u64>,
|
||||
/// Excluded Files, under the folder list.
|
||||
pub(crate) exclusions: ExclusionsState,
|
||||
}
|
||||
|
||||
/// The status card heading the Sync page's Overview, and Pause/Resume in the
|
||||
@@ -120,6 +122,8 @@ pub(crate) struct LocationsWidgets {
|
||||
pub(crate) conflicts_group: adw::PreferencesGroup,
|
||||
pub(crate) views: adw::ViewStack,
|
||||
pub(crate) banner: adw::Banner,
|
||||
pub(crate) exclusions_group: adw::PreferencesGroup,
|
||||
pub(crate) add_pattern: gtk4::Button,
|
||||
}
|
||||
|
||||
/// The Sync page: Overview (the status, conflicts, transfers and queue),
|
||||
@@ -208,8 +212,14 @@ pub(crate) fn build_locations_page(history: >k4::Widget) -> (gtk4::Widget, Loc
|
||||
.child(&status)
|
||||
.build();
|
||||
|
||||
// What the folders leave out, under them: the rules belong to the folders.
|
||||
let (exclusions_group, add_pattern) = build_exclusions_group();
|
||||
let folders = gtk4::Box::new(gtk4::Orientation::Vertical, 24);
|
||||
folders.append(&group);
|
||||
folders.append(&exclusions_group);
|
||||
|
||||
let content = gtk4::Stack::new();
|
||||
content.add_named(&scrolled_column(&group), Some("list"));
|
||||
content.add_named(&scrolled_column(&folders), Some("list"));
|
||||
content.add_named(&status_scroll, Some("status"));
|
||||
|
||||
let views = adw::ViewStack::new();
|
||||
@@ -267,6 +277,8 @@ pub(crate) fn build_locations_page(history: >k4::Widget) -> (gtk4::Widget, Loc
|
||||
conflicts_group,
|
||||
views,
|
||||
banner,
|
||||
exclusions_group,
|
||||
add_pattern,
|
||||
};
|
||||
(frame.upcast(), widgets)
|
||||
}
|
||||
@@ -776,6 +788,9 @@ pub(crate) fn issue_text(issue: SyncIssue) -> String {
|
||||
SyncIssue::Access => gettext(
|
||||
"You can no longer change this on Proton Drive. Ask the owner for edit access, or export the file to keep your version.",
|
||||
),
|
||||
SyncIssue::Trashed => {
|
||||
gettext("Restore the item or folder from Trash, then retry the move.")
|
||||
}
|
||||
SyncIssue::Missing => gettext(
|
||||
"The folder this change belongs in is gone from Proton Drive. Export the file to keep your version.",
|
||||
),
|
||||
@@ -1243,6 +1258,7 @@ pub(crate) fn repaint_locations(ui: &Rc<Ui>, items: &[MountSpec]) {
|
||||
};
|
||||
if !unchanged {
|
||||
rebuild_locations(ui, items, keys);
|
||||
paint_exclusions(ui, items);
|
||||
}
|
||||
for (row, spec) in ui.locations.rows.borrow().iter().zip(items) {
|
||||
update_location_row(row, spec);
|
||||
@@ -1498,6 +1514,7 @@ fn folder_mode_label(ondemand: bool) -> String {
|
||||
/// synced folder's menu.
|
||||
fn add_device_items(ui: &Rc<Ui>, menu: &mut ActionMenu, spec: &MountSpec, id: i64) {
|
||||
if spec.mode != MountMode::OnDemand {
|
||||
let ui_ignore = ui.clone();
|
||||
// A paused folder skips its passes, so Sync now would do nothing.
|
||||
if !spec.paused {
|
||||
let ui = ui.clone();
|
||||
@@ -1516,6 +1533,14 @@ fn add_device_items(ui: &Rc<Ui>, menu: &mut ActionMenu, spec: &MountSpec, id: i6
|
||||
menu.item(&gettext("Sync From Scratch…"), move || {
|
||||
confirm_reset_sync_folder(&ui, id, &path)
|
||||
});
|
||||
// Only a synced copy has local files for the rules to leave out.
|
||||
if spec.mode == MountMode::Mirror {
|
||||
let ui = ui_ignore;
|
||||
let root = PathBuf::from(&spec.local_path);
|
||||
menu.item(&gettext("Excluded Files…"), move || {
|
||||
present_ignore_dialog(&ui, id, root.clone())
|
||||
});
|
||||
}
|
||||
menu.section();
|
||||
}
|
||||
let ui = ui.clone();
|
||||
|
||||
@@ -683,6 +683,10 @@ pub(crate) fn sign_out(ui: &Rc<Ui>) {
|
||||
),
|
||||
&gettext("Sign Out"),
|
||||
move || {
|
||||
let galleries = ui.drive_galleries.borrow().upgrade();
|
||||
if let Some(galleries) = galleries {
|
||||
galleries.reset();
|
||||
}
|
||||
// systemctl and the keyring both block, so run them on a worker.
|
||||
let ui = ui.clone();
|
||||
glib::spawn_future_local(async move {
|
||||
|
||||
@@ -3,6 +3,7 @@ pub(crate) mod activity_text;
|
||||
pub(crate) mod albums;
|
||||
pub(crate) mod browser;
|
||||
pub(crate) mod devices;
|
||||
pub(crate) mod drive_galleries;
|
||||
pub(crate) mod duplicates;
|
||||
pub(crate) mod locations;
|
||||
pub(crate) mod login;
|
||||
@@ -12,9 +13,12 @@ pub(crate) mod photo_viewer;
|
||||
pub(crate) mod photos;
|
||||
pub(crate) mod places;
|
||||
pub(crate) mod places_map;
|
||||
pub(crate) mod preferences_apps;
|
||||
pub(crate) mod preferences_sync;
|
||||
pub(crate) mod shared;
|
||||
pub(crate) mod shared_by_me;
|
||||
pub(crate) mod status;
|
||||
pub(crate) mod sync_exclusions;
|
||||
pub(crate) mod takeout;
|
||||
pub(crate) mod trash;
|
||||
pub(crate) mod verify;
|
||||
@@ -31,6 +31,11 @@ pub(crate) struct Viewer {
|
||||
pub(crate) scroller: gtk4::ScrolledWindow,
|
||||
pub(crate) picture: gtk4::Picture,
|
||||
pub(crate) video: gtk4::Video,
|
||||
video_token: RefCell<Option<String>>,
|
||||
load_generation: Cell<u64>,
|
||||
presence_loading: Cell<bool>,
|
||||
presence_pending: Cell<bool>,
|
||||
album: Option<String>,
|
||||
pub(crate) spinner: Spinner,
|
||||
pub(crate) status: gtk4::Label,
|
||||
pub(crate) title: gtk4::Label,
|
||||
@@ -272,12 +277,14 @@ fn viewer_item(ui: &Rc<Ui>, viewer: &Rc<Viewer>, uid: &str) -> Option<PhotoItem>
|
||||
/// full-size file, and swap it in — plus its EXIF — when it lands. A video
|
||||
/// plays in place once its file is down.
|
||||
pub(crate) fn load_photo(ui: &Rc<Ui>, viewer: &Rc<Viewer>, uid: String) {
|
||||
let generation = viewer.load_generation.get().wrapping_add(1);
|
||||
viewer.load_generation.set(generation);
|
||||
viewer.spinner.set_visible(true);
|
||||
viewer.status.set_visible(false);
|
||||
viewer.loading.set(true);
|
||||
*viewer.path.borrow_mut() = None;
|
||||
clear_info(viewer);
|
||||
stop_video(viewer);
|
||||
stop_video(ui, viewer);
|
||||
viewer.media.set_visible_child_name("photo");
|
||||
sync_strip(viewer);
|
||||
reset_zoom(viewer);
|
||||
@@ -302,17 +309,25 @@ pub(crate) fn load_photo(ui: &Rc<Ui>, viewer: &Rc<Viewer>, uid: String) {
|
||||
None => viewer.picture.set_paintable(gtk4::gdk::Paintable::NONE),
|
||||
}
|
||||
|
||||
let rx = spawn_request(
|
||||
ui.dirs.control_socket(),
|
||||
Request::OpenPhoto { uid: uid.clone() },
|
||||
);
|
||||
let request = if is_video {
|
||||
Request::OpenGalleryVideo {
|
||||
uid: uid.clone(),
|
||||
private: false,
|
||||
}
|
||||
} else {
|
||||
Request::OpenPhoto { uid: uid.clone() }
|
||||
};
|
||||
let rx = spawn_request(ui.dirs.control_socket(), request);
|
||||
let viewer = viewer.clone();
|
||||
let ui = ui.clone();
|
||||
glib::spawn_future_local(async move {
|
||||
let result = rx.recv().await;
|
||||
// The user may have moved on while this was in flight; that photo's own
|
||||
// request owns the viewer now.
|
||||
if *viewer.uid.borrow() != uid {
|
||||
if viewer.load_generation.get() != generation {
|
||||
if let Ok(Ok(Response::GalleryVideo { token, .. })) = result {
|
||||
close_video(&ui, token);
|
||||
}
|
||||
return;
|
||||
}
|
||||
viewer.spinner.set_visible(false);
|
||||
@@ -326,6 +341,14 @@ pub(crate) fn load_photo(ui: &Rc<Ui>, viewer: &Rc<Viewer>, uid: String) {
|
||||
viewer.status.set_visible(true);
|
||||
};
|
||||
let path = match result {
|
||||
Ok(Ok(Response::GalleryVideo { url, token, size })) => {
|
||||
*viewer.video_token.borrow_mut() = Some(token);
|
||||
viewer.video.set_file(Some(&gio::File::for_uri(&url)));
|
||||
viewer.media.set_visible_child_name("video");
|
||||
sync_strip(&viewer);
|
||||
show_info(&viewer, Some(size), ExifInfo::default());
|
||||
return;
|
||||
}
|
||||
Ok(Ok(Response::FilePath { path })) => path,
|
||||
Ok(Ok(Response::Error { message, .. })) => return fail(&message),
|
||||
Ok(Ok(_)) => return fail(&gettext("Unexpected reply from the Proton Drive service.")),
|
||||
@@ -481,8 +504,18 @@ fn next_slide(ui: &Rc<Ui>, viewer: &Rc<Viewer>) {
|
||||
|
||||
/// Stop whatever the player was playing, so stepping off a video (or closing
|
||||
/// the lightbox) doesn't leave its sound running.
|
||||
fn stop_video(viewer: &Rc<Viewer>) {
|
||||
fn close_video(ui: &Ui, token: String) {
|
||||
let _reply = spawn_request(
|
||||
ui.dirs.control_socket(),
|
||||
Request::CloseGalleryVideo { token },
|
||||
);
|
||||
}
|
||||
|
||||
fn stop_video(ui: &Ui, viewer: &Rc<Viewer>) {
|
||||
viewer.video.set_media_stream(gtk4::MediaStream::NONE);
|
||||
if let Some(token) = viewer.video_token.borrow_mut().take() {
|
||||
close_video(ui, token);
|
||||
}
|
||||
}
|
||||
|
||||
/// Warm the cache with the photo `delta` steps away, so stepping there is
|
||||
@@ -1210,6 +1243,43 @@ fn build_strip(ui: &Rc<Ui>) -> (gtk4::ListView, gtk4::SingleSelection) {
|
||||
///
|
||||
/// Returns the lightbox's window, for a caller that has to put the page
|
||||
/// behind it back once it closes.
|
||||
pub(crate) fn check_photo_viewer(ui: &Rc<Ui>) {
|
||||
let Some(viewer) = ui.gallery.viewer.borrow().upgrade() else {
|
||||
return;
|
||||
};
|
||||
if !viewer.window.is_visible() {
|
||||
return;
|
||||
}
|
||||
if viewer.presence_loading.replace(true) {
|
||||
viewer.presence_pending.set(true);
|
||||
return;
|
||||
}
|
||||
let uid = viewer.uid.borrow().clone();
|
||||
let rx = spawn_request(
|
||||
ui.dirs.control_socket(),
|
||||
Request::PhotoPresence {
|
||||
uid: uid.clone(),
|
||||
album: viewer.album.clone(),
|
||||
},
|
||||
);
|
||||
let ui = ui.clone();
|
||||
let viewer = Rc::downgrade(&viewer);
|
||||
glib::spawn_future_local(async move {
|
||||
let result = rx.recv().await;
|
||||
let Some(viewer) = viewer.upgrade() else {
|
||||
return;
|
||||
};
|
||||
viewer.presence_loading.set(false);
|
||||
if *viewer.uid.borrow() == uid
|
||||
&& matches!(result, Ok(Ok(Response::PhotoPresence { present: false })))
|
||||
{
|
||||
viewer.window.close();
|
||||
} else if viewer.presence_pending.replace(false) {
|
||||
check_photo_viewer(&ui);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
pub(crate) fn open_photo_viewer(ui: &Rc<Ui>, initial_uid: String) -> gtk4::Window {
|
||||
let parent = ui.stack.root().and_downcast::<gtk4::Window>().unwrap();
|
||||
|
||||
@@ -1473,6 +1543,16 @@ pub(crate) fn open_photo_viewer(ui: &Rc<Ui>, initial_uid: String) -> gtk4::Windo
|
||||
scroller: scroller.clone(),
|
||||
picture: picture.clone(),
|
||||
video,
|
||||
video_token: RefCell::new(None),
|
||||
load_generation: Cell::new(0),
|
||||
presence_loading: Cell::new(false),
|
||||
presence_pending: Cell::new(false),
|
||||
album: ui
|
||||
.gallery
|
||||
.album
|
||||
.borrow()
|
||||
.as_ref()
|
||||
.map(|album| album.uid.clone()),
|
||||
spinner,
|
||||
status: status_label,
|
||||
title: title_label,
|
||||
@@ -1515,6 +1595,7 @@ pub(crate) fn open_photo_viewer(ui: &Rc<Ui>, initial_uid: String) -> gtk4::Windo
|
||||
toasts,
|
||||
});
|
||||
|
||||
*ui.gallery.viewer.borrow_mut() = Rc::downgrade(&viewer);
|
||||
let initial_idx = find_photo_index(&ui.gallery.model, &initial_uid).unwrap_or(0);
|
||||
let capture_time = viewer_item(ui, &viewer, &initial_uid).map_or(0, |item| item.capture_time);
|
||||
show_photo_position(ui, &viewer, initial_idx, capture_time);
|
||||
@@ -1700,7 +1781,10 @@ pub(crate) fn open_photo_viewer(ui: &Rc<Ui>, initial_uid: String) -> gtk4::Windo
|
||||
}
|
||||
if let Some(viewer) = keep.borrow_mut().take() {
|
||||
reveal_photo(&ui_close, &viewer.uid.borrow());
|
||||
stop_video(&viewer);
|
||||
viewer
|
||||
.load_generation
|
||||
.set(viewer.load_generation.get().wrapping_add(1));
|
||||
stop_video(&ui_close, &viewer);
|
||||
disarm_slide(&viewer);
|
||||
if let Some(source) = viewer.chrome_source.borrow_mut().take() {
|
||||
source.remove();
|
||||
@@ -1952,7 +2036,7 @@ fn open_viewer_menu(ui: &Rc<Ui>, viewer: &Rc<Viewer>) {
|
||||
}
|
||||
menu.section();
|
||||
// These need the full-size file, which may still be downloading.
|
||||
if viewer.path.borrow().is_some() {
|
||||
if viewer.path.borrow().is_some() || viewer.video_token.borrow().is_some() {
|
||||
let still = viewer.media.visible_child_name().as_deref() == Some("photo");
|
||||
if still {
|
||||
// Translators: menu item that puts the photo on the clipboard as an image.
|
||||
@@ -1999,17 +2083,45 @@ fn open_viewer_menu(ui: &Rc<Ui>, viewer: &Rc<Viewer>) {
|
||||
});
|
||||
}
|
||||
|
||||
fn save_shown_photo(_ui: &Rc<Ui>, viewer: &Rc<Viewer>) {
|
||||
if let Some(path) = viewer.path.borrow().as_deref() {
|
||||
let name = viewer.name.borrow();
|
||||
save_photo_to_disk(viewer, path, name.as_deref().unwrap_or("photo"));
|
||||
}
|
||||
fn save_shown_photo(ui: &Rc<Ui>, viewer: &Rc<Viewer>) {
|
||||
with_viewer_file(ui, viewer, |viewer, path, name| {
|
||||
save_photo_to_disk(viewer, path, name.unwrap_or("photo"))
|
||||
});
|
||||
}
|
||||
|
||||
fn open_shown_photo(_ui: &Rc<Ui>, viewer: &Rc<Viewer>) {
|
||||
fn open_shown_photo(ui: &Rc<Ui>, viewer: &Rc<Viewer>) {
|
||||
with_viewer_file(ui, viewer, |viewer, path, name| {
|
||||
open_with(&viewer.window, path, name)
|
||||
});
|
||||
}
|
||||
|
||||
fn with_viewer_file(
|
||||
ui: &Rc<Ui>,
|
||||
viewer: &Rc<Viewer>,
|
||||
use_file: impl FnOnce(&Rc<Viewer>, &str, Option<&str>) + 'static,
|
||||
) {
|
||||
let name = viewer.name.borrow().clone();
|
||||
if let Some(path) = viewer.path.borrow().as_deref() {
|
||||
open_with(&viewer.window, path, viewer.name.borrow().as_deref());
|
||||
use_file(viewer, path, name.as_deref());
|
||||
return;
|
||||
}
|
||||
if viewer.video_token.borrow().is_none() {
|
||||
return;
|
||||
}
|
||||
let uid = viewer.uid.borrow().clone();
|
||||
let viewer = viewer.clone();
|
||||
let rx = spawn_request(ui.dirs.control_socket(), Request::OpenPhoto { uid });
|
||||
glib::spawn_future_local(async move {
|
||||
match rx.recv().await {
|
||||
Ok(Ok(Response::FilePath { path })) => use_file(&viewer, &path, name.as_deref()),
|
||||
Ok(Ok(Response::Error { message, .. })) => {
|
||||
viewer.toasts.add_toast(adw::Toast::new(&message))
|
||||
}
|
||||
_ => viewer
|
||||
.toasts
|
||||
.add_toast(adw::Toast::new(&gettext("Couldn't open the file."))),
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fn add_shown_photo_to_album(ui: &Rc<Ui>, viewer: &Rc<Viewer>) {
|
||||
|
||||
@@ -0,0 +1,606 @@
|
||||
//! Preferences → Apps: which program opens which file (`open_with`) and how
|
||||
//! the search launcher shows itself (`prompt`).
|
||||
//!
|
||||
//! Neither involves the service. The app and the search launcher read both
|
||||
//! again each time they open something, so a change applies to the next file
|
||||
//! opened or the next search.
|
||||
|
||||
use crate::*;
|
||||
use pdfs_core::menu::{PromptConfig, PromptMode};
|
||||
use pdfs_core::opener::{
|
||||
OpenRule, OpenWith, command_available, format_command, parse_command, resolve_terminal,
|
||||
};
|
||||
|
||||
/// The widgets of the Apps page, built with the rest of the dialog and wired
|
||||
/// once the app's state exists.
|
||||
pub(crate) struct AppsPrefs {
|
||||
pub(crate) page: adw::PreferencesPage,
|
||||
rules: adw::PreferencesGroup,
|
||||
add_rule: gtk4::Button,
|
||||
other_row: adw::EntryRow,
|
||||
terminal_row: adw::EntryRow,
|
||||
mode_row: adw::ComboRow,
|
||||
menu_row: adw::EntryRow,
|
||||
prompt_terminal_row: adw::EntryRow,
|
||||
limit_row: adw::SpinRow,
|
||||
icons_row: adw::SwitchRow,
|
||||
}
|
||||
|
||||
/// The launcher modes in the order the combo row lists them.
|
||||
const MODES: [PromptMode; 3] = [PromptMode::Gtk, PromptMode::Dmenu, PromptMode::Fzf];
|
||||
|
||||
/// The file classes a rule can name, with what the dialog calls them.
|
||||
fn classes() -> [(&'static str, String); 6] {
|
||||
[
|
||||
("@text", gettext("Text")),
|
||||
("@document", gettext("Documents")),
|
||||
("@image", gettext("Images")),
|
||||
("@media", gettext("Audio and Video")),
|
||||
("@dir", gettext("Folders")),
|
||||
("@any", gettext("Everything")),
|
||||
]
|
||||
}
|
||||
|
||||
pub(crate) fn build_apps_prefs() -> AppsPrefs {
|
||||
let add_rule = gtk4::Button::builder()
|
||||
.label(gettext("Add Rule…"))
|
||||
.valign(gtk4::Align::Center)
|
||||
.build();
|
||||
add_rule.add_css_class("flat");
|
||||
let rules = adw::PreferencesGroup::builder()
|
||||
.title(gettext("Open Files With"))
|
||||
.description(gettext(
|
||||
"For files opened from Proton Drive and the search launcher. The first rule that matches a file decides; other files open in their default app.",
|
||||
))
|
||||
.header_suffix(&add_rule)
|
||||
.build();
|
||||
|
||||
let other_row = adw::EntryRow::builder()
|
||||
.title(gettext("Other files (empty: default app)"))
|
||||
.show_apply_button(true)
|
||||
.build();
|
||||
other_row.add_css_class("monospace");
|
||||
let terminal_row = adw::EntryRow::builder()
|
||||
.title(terminal_title())
|
||||
.show_apply_button(true)
|
||||
.build();
|
||||
terminal_row.add_css_class("monospace");
|
||||
let other = adw::PreferencesGroup::new();
|
||||
other.add(&other_row);
|
||||
other.add(&terminal_row);
|
||||
|
||||
let mode_row = adw::ComboRow::builder()
|
||||
.title(gettext("Opens as"))
|
||||
.model(>k4::StringList::new(&[
|
||||
&gettext("Window"),
|
||||
&gettext("Your Launcher"),
|
||||
&gettext("fzf in a Terminal"),
|
||||
]))
|
||||
.build();
|
||||
let menu_row = adw::EntryRow::builder()
|
||||
.title(gettext("Launcher command (empty: find one)"))
|
||||
.show_apply_button(true)
|
||||
.build();
|
||||
menu_row.add_css_class("monospace");
|
||||
let prompt_terminal_row = adw::EntryRow::builder()
|
||||
.title(terminal_title())
|
||||
.show_apply_button(true)
|
||||
.build();
|
||||
prompt_terminal_row.add_css_class("monospace");
|
||||
let limit_row = adw::SpinRow::builder()
|
||||
.title(gettext("Results shown"))
|
||||
.adjustment(>k4::Adjustment::new(
|
||||
pdfs_core::menu::DEFAULT_MENU_LIMIT as f64,
|
||||
5.0,
|
||||
500.0,
|
||||
5.0,
|
||||
25.0,
|
||||
0.0,
|
||||
))
|
||||
.build();
|
||||
let icons_row = adw::SwitchRow::builder()
|
||||
.title(gettext("Show icons"))
|
||||
.subtitle(gettext("When the launcher can show them"))
|
||||
.build();
|
||||
let launcher = adw::PreferencesGroup::builder()
|
||||
.title(gettext("Search Launcher"))
|
||||
.description(gettext(
|
||||
"How “pdfs-prompt” shows search results, for example from a keyboard shortcut. Your launcher can be any program that reads choices like dmenu, such as rofi, wofi, fuzzel or bemenu.",
|
||||
))
|
||||
.build();
|
||||
launcher.add(&mode_row);
|
||||
launcher.add(&menu_row);
|
||||
launcher.add(&prompt_terminal_row);
|
||||
launcher.add(&limit_row);
|
||||
launcher.add(&icons_row);
|
||||
|
||||
let page = adw::PreferencesPage::builder()
|
||||
.title(gettext("Apps"))
|
||||
.name("apps")
|
||||
.icon_name("application-x-executable-symbolic")
|
||||
.build();
|
||||
page.add(&rules);
|
||||
page.add(&other);
|
||||
page.add(&launcher);
|
||||
AppsPrefs {
|
||||
page,
|
||||
rules,
|
||||
add_rule,
|
||||
other_row,
|
||||
terminal_row,
|
||||
mode_row,
|
||||
menu_row,
|
||||
prompt_terminal_row,
|
||||
limit_row,
|
||||
icons_row,
|
||||
}
|
||||
}
|
||||
|
||||
/// "Terminal", naming the one used when the row is left empty.
|
||||
fn terminal_title() -> String {
|
||||
match resolve_terminal() {
|
||||
// Translators: {terminal} is a terminal command line such as "foot -e".
|
||||
Some(found) => gettext_f(
|
||||
"Terminal (empty: {terminal})",
|
||||
&[("terminal", &format_command(&found))],
|
||||
),
|
||||
None => gettext("Terminal"),
|
||||
}
|
||||
}
|
||||
|
||||
/// Shared by every handler of the page.
|
||||
struct Apps {
|
||||
ui: Rc<Ui>,
|
||||
widgets: AppsPrefs,
|
||||
rule_rows: RefCell<Vec<adw::ActionRow>>,
|
||||
}
|
||||
|
||||
/// Fill the page from the config and connect its controls.
|
||||
pub(crate) fn wire_apps_prefs(ui: &Rc<Ui>, widgets: AppsPrefs) {
|
||||
let apps = Rc::new(Apps {
|
||||
ui: ui.clone(),
|
||||
widgets,
|
||||
rule_rows: RefCell::default(),
|
||||
});
|
||||
let config = ui.dirs.load_config();
|
||||
let open_with = config.resolved_open_with();
|
||||
let prompt = config.resolved_prompt();
|
||||
let w = &apps.widgets;
|
||||
|
||||
let suppress = ui.status.settings_suppress.replace(true);
|
||||
paint_rules(&apps, &open_with);
|
||||
w.other_row
|
||||
.set_text(&format_command(open_with.default.as_deref().unwrap_or(&[])));
|
||||
w.terminal_row.set_text(&format_command(
|
||||
open_with.terminal.as_deref().unwrap_or(&[]),
|
||||
));
|
||||
let mode = prompt.resolved_mode();
|
||||
w.mode_row
|
||||
.set_selected(MODES.iter().position(|m| *m == mode).unwrap_or_default() as u32);
|
||||
w.menu_row
|
||||
.set_text(&format_command(prompt.menu.as_deref().unwrap_or(&[])));
|
||||
w.prompt_terminal_row
|
||||
.set_text(&format_command(prompt.terminal.as_deref().unwrap_or(&[])));
|
||||
w.limit_row.set_value(prompt.resolved_menu_limit() as f64);
|
||||
w.icons_row.set_active(prompt.resolved_menu_icons());
|
||||
show_mode_rows(w, mode);
|
||||
ui.status.settings_suppress.set(suppress);
|
||||
|
||||
let a = apps.clone();
|
||||
w.add_rule
|
||||
.connect_clicked(move |_| edit_rule(&a, None, OpenRule::default()));
|
||||
|
||||
// Command lines: checked as typed, saved on apply. Empty means "unset".
|
||||
connect_command_row(&apps, &w.other_row, |config, argv| {
|
||||
open_with_of(config).default = argv;
|
||||
});
|
||||
connect_command_row(&apps, &w.terminal_row, |config, argv| {
|
||||
open_with_of(config).terminal = argv;
|
||||
});
|
||||
connect_command_row(&apps, &w.menu_row, |config, argv| {
|
||||
prompt_of(config).menu = argv;
|
||||
});
|
||||
connect_command_row(&apps, &w.prompt_terminal_row, |config, argv| {
|
||||
prompt_of(config).terminal = argv;
|
||||
});
|
||||
|
||||
let a = apps.clone();
|
||||
w.mode_row.connect_selected_notify(move |row| {
|
||||
if a.ui.status.settings_suppress.get() {
|
||||
return;
|
||||
}
|
||||
let mode = MODES
|
||||
.get(row.selected() as usize)
|
||||
.copied()
|
||||
.unwrap_or_default();
|
||||
show_mode_rows(&a.widgets, mode);
|
||||
save(&a, move |config| {
|
||||
prompt_of(config).mode = (mode != PromptMode::default()).then_some(mode);
|
||||
});
|
||||
});
|
||||
let a = apps.clone();
|
||||
w.limit_row.connect_value_notify(move |row| {
|
||||
if a.ui.status.settings_suppress.get() {
|
||||
return;
|
||||
}
|
||||
let limit = row.value().round() as usize;
|
||||
save(&a, move |config| {
|
||||
prompt_of(config).menu_limit =
|
||||
(limit != pdfs_core::menu::DEFAULT_MENU_LIMIT).then_some(limit);
|
||||
});
|
||||
});
|
||||
let a = apps.clone();
|
||||
w.icons_row.connect_active_notify(move |row| {
|
||||
if a.ui.status.settings_suppress.get() {
|
||||
return;
|
||||
}
|
||||
let on = row.is_active();
|
||||
save(&a, move |config| {
|
||||
prompt_of(config).menu_icons = (!on).then_some(false)
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/// Show only the rows the chosen launcher mode uses.
|
||||
fn show_mode_rows(w: &AppsPrefs, mode: PromptMode) {
|
||||
w.menu_row.set_visible(mode == PromptMode::Dmenu);
|
||||
w.icons_row.set_visible(mode == PromptMode::Dmenu);
|
||||
w.prompt_terminal_row.set_visible(mode == PromptMode::Fzf);
|
||||
w.limit_row.set_visible(mode != PromptMode::Gtk);
|
||||
}
|
||||
|
||||
/// The `open_with` section, created when absent.
|
||||
fn open_with_of(config: &mut pdfs_core::config::AppConfig) -> &mut OpenWith {
|
||||
config.open_with.get_or_insert_with(OpenWith::default)
|
||||
}
|
||||
|
||||
/// The `prompt` section, created when absent.
|
||||
fn prompt_of(config: &mut pdfs_core::config::AppConfig) -> &mut PromptConfig {
|
||||
config.prompt.get_or_insert_with(PromptConfig::default)
|
||||
}
|
||||
|
||||
/// Save a change, then drop sections left at their defaults so the file only
|
||||
/// holds what the user chose. Says whether it saved.
|
||||
fn save(apps: &Rc<Apps>, change: impl FnOnce(&mut pdfs_core::config::AppConfig)) -> bool {
|
||||
let saved = apps.ui.dirs.update_config(|config| {
|
||||
change(config);
|
||||
if config.open_with.as_ref() == Some(&OpenWith::default()) {
|
||||
config.open_with = None;
|
||||
}
|
||||
if config.prompt.as_ref() == Some(&PromptConfig::default()) {
|
||||
config.prompt = None;
|
||||
}
|
||||
config.resolved_open_with()
|
||||
});
|
||||
match saved {
|
||||
Ok(open_with) => {
|
||||
paint_rules(apps, &open_with);
|
||||
true
|
||||
}
|
||||
Err(e) => {
|
||||
prefs_toast(
|
||||
&apps.ui,
|
||||
&gettext_f(
|
||||
"{what}: {detail}",
|
||||
&[
|
||||
("what", &gettext("Couldn't save the setting")),
|
||||
("detail", &e.to_string()),
|
||||
],
|
||||
),
|
||||
);
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Check a command line as it is typed, and save it when applied.
|
||||
fn connect_command_row(
|
||||
apps: &Rc<Apps>,
|
||||
row: &adw::EntryRow,
|
||||
store: impl Fn(&mut pdfs_core::config::AppConfig, Option<Vec<String>>) + 'static,
|
||||
) {
|
||||
row.connect_changed(|row| mark_command(row, false));
|
||||
let a = apps.clone();
|
||||
row.connect_apply(move |row| {
|
||||
let Some(argv) = parse_command(&row.text()) else {
|
||||
prefs_toast(&a.ui, &gettext("A quote is not closed in the command"));
|
||||
return;
|
||||
};
|
||||
if !argv.is_empty() && !command_available(&argv) {
|
||||
prefs_toast(
|
||||
&a.ui,
|
||||
// Translators: {program} is a program name such as "nvim".
|
||||
&gettext_f(
|
||||
"“{program}” isn't installed; saved anyway",
|
||||
&[("program", &argv[0])],
|
||||
),
|
||||
);
|
||||
}
|
||||
let argv = (!argv.is_empty()).then_some(argv);
|
||||
save(&a, |config| store(config, argv));
|
||||
mark_command(row, true);
|
||||
});
|
||||
}
|
||||
|
||||
/// Mark a command line that doesn't parse as an error, and, once `applied`,
|
||||
/// one whose program isn't found as a warning.
|
||||
fn mark_command(row: &adw::EntryRow, applied: bool) {
|
||||
row.remove_css_class("error");
|
||||
row.remove_css_class("warning");
|
||||
match parse_command(&row.text()) {
|
||||
None => row.add_css_class("error"),
|
||||
Some(argv) if applied && !argv.is_empty() && !command_available(&argv) => {
|
||||
row.add_css_class("warning")
|
||||
}
|
||||
Some(_) => {}
|
||||
}
|
||||
}
|
||||
|
||||
/// Show the rules, one row each, in the order they are tried.
|
||||
fn paint_rules(apps: &Rc<Apps>, open_with: &OpenWith) {
|
||||
let group = &apps.widgets.rules;
|
||||
for row in apps.rule_rows.borrow_mut().drain(..) {
|
||||
group.remove(&row);
|
||||
}
|
||||
let count = open_with.rules.len();
|
||||
if count == 0 {
|
||||
let row = adw::ActionRow::builder()
|
||||
.title(gettext("No rules: every file opens in its default app"))
|
||||
.build();
|
||||
row.add_css_class("dim-label");
|
||||
group.add(&row);
|
||||
apps.rule_rows.borrow_mut().push(row);
|
||||
return;
|
||||
}
|
||||
let names = classes();
|
||||
for (index, rule) in open_with.rules.iter().enumerate() {
|
||||
let patterns: Vec<String> = rule
|
||||
.patterns
|
||||
.iter()
|
||||
.map(|p| {
|
||||
names
|
||||
.iter()
|
||||
.find(|(class, _)| class == p)
|
||||
.map_or_else(|| p.clone(), |(_, name)| name.clone())
|
||||
})
|
||||
.collect();
|
||||
let command = format_command(&rule.command);
|
||||
let subtitle = if rule.terminal {
|
||||
// Translators: {command} is a command line such as "nvim".
|
||||
gettext_f("{command}, in a terminal", &[("command", &command)])
|
||||
} else {
|
||||
command
|
||||
};
|
||||
let row = adw::ActionRow::builder()
|
||||
.title(patterns.join(", "))
|
||||
.subtitle(subtitle)
|
||||
.use_markup(false)
|
||||
.activatable(true)
|
||||
.build();
|
||||
if !command_available(&rule.command) {
|
||||
let warning = gtk4::Image::builder()
|
||||
.icon_name("dialog-warning-symbolic")
|
||||
// Translators: {program} is a program name such as "nvim".
|
||||
.tooltip_text(gettext_f(
|
||||
"“{program}” isn't installed",
|
||||
&[("program", rule.command.first().map_or("", String::as_str))],
|
||||
))
|
||||
.build();
|
||||
warning.add_css_class("warning");
|
||||
row.add_prefix(&warning);
|
||||
}
|
||||
let up = rule_button("go-up-symbolic", &gettext("Move Up"), index > 0);
|
||||
let down = rule_button("go-down-symbolic", &gettext("Move Down"), index + 1 < count);
|
||||
let remove = rule_button("user-trash-symbolic", &gettext("Remove"), true);
|
||||
let a = apps.clone();
|
||||
up.connect_clicked(move |_| {
|
||||
save(&a, |config| {
|
||||
open_with_of(config).rules.swap(index - 1, index)
|
||||
});
|
||||
});
|
||||
let a = apps.clone();
|
||||
down.connect_clicked(move |_| {
|
||||
save(&a, |config| {
|
||||
open_with_of(config).rules.swap(index, index + 1)
|
||||
});
|
||||
});
|
||||
let a = apps.clone();
|
||||
remove.connect_clicked(move |_| {
|
||||
save(&a, |config| {
|
||||
let rules = &mut open_with_of(config).rules;
|
||||
if index < rules.len() {
|
||||
rules.remove(index);
|
||||
}
|
||||
});
|
||||
});
|
||||
row.add_suffix(&up);
|
||||
row.add_suffix(&down);
|
||||
row.add_suffix(&remove);
|
||||
let a = apps.clone();
|
||||
let rule = rule.clone();
|
||||
row.connect_activated(move |_| edit_rule(&a, Some(index), rule.clone()));
|
||||
group.add(&row);
|
||||
apps.rule_rows.borrow_mut().push(row);
|
||||
}
|
||||
}
|
||||
|
||||
fn rule_button(icon: &str, tooltip: &str, sensitive: bool) -> gtk4::Button {
|
||||
let button = gtk4::Button::builder()
|
||||
.icon_name(icon)
|
||||
.tooltip_text(tooltip)
|
||||
.valign(gtk4::Align::Center)
|
||||
.sensitive(sensitive)
|
||||
.build();
|
||||
button.add_css_class("flat");
|
||||
button
|
||||
}
|
||||
|
||||
/// Split a typed pattern list into patterns, dropping empty ones.
|
||||
fn split_patterns(text: &str) -> Vec<String> {
|
||||
text.split(',')
|
||||
.map(str::trim)
|
||||
.filter(|p| !p.is_empty())
|
||||
.map(str::to_string)
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Edit one rule, or a new one when `index` is `None`, in a dialog over the
|
||||
/// Preferences.
|
||||
fn edit_rule(apps: &Rc<Apps>, index: Option<usize>, rule: OpenRule) {
|
||||
let patterns_row = adw::EntryRow::builder()
|
||||
.title(gettext("Files, such as *.md, *.txt"))
|
||||
.text(rule.patterns.join(", "))
|
||||
.build();
|
||||
patterns_row.add_css_class("monospace");
|
||||
let chips = gtk4::FlowBox::builder()
|
||||
.selection_mode(gtk4::SelectionMode::None)
|
||||
.column_spacing(6)
|
||||
.row_spacing(6)
|
||||
.max_children_per_line(6)
|
||||
.margin_top(6)
|
||||
.build();
|
||||
for (class, name) in classes() {
|
||||
let chip = gtk4::Button::builder().label(&name).build();
|
||||
chip.add_css_class("pill");
|
||||
chip.add_css_class("small");
|
||||
let row = patterns_row.clone();
|
||||
chip.connect_clicked(move |_| {
|
||||
let mut list = split_patterns(&row.text());
|
||||
if !list.iter().any(|p| p == class) {
|
||||
list.push(class.to_string());
|
||||
}
|
||||
row.set_text(&list.join(", "));
|
||||
});
|
||||
chips.insert(&chip, -1);
|
||||
}
|
||||
let command_row = adw::EntryRow::builder()
|
||||
.title(gettext("Command, such as nvim or code --wait"))
|
||||
.text(format_command(&rule.command))
|
||||
.build();
|
||||
command_row.add_css_class("monospace");
|
||||
let terminal_row = adw::SwitchRow::builder()
|
||||
.title(gettext("Run in a terminal"))
|
||||
.subtitle(gettext("For programs that run in a terminal, such as vim"))
|
||||
.active(rule.terminal)
|
||||
.build();
|
||||
let hint = gtk4::Label::builder()
|
||||
.wrap(true)
|
||||
.xalign(0.0)
|
||||
.margin_top(6)
|
||||
.build();
|
||||
hint.add_css_class("caption");
|
||||
hint.add_css_class("dim-label");
|
||||
|
||||
let group = adw::PreferencesGroup::new();
|
||||
group.add(&patterns_row);
|
||||
let files = adw::PreferencesGroup::builder()
|
||||
.description(gettext("Or pick kinds of files:"))
|
||||
.build();
|
||||
files.add(&chips);
|
||||
let program = adw::PreferencesGroup::new();
|
||||
program.add(&command_row);
|
||||
program.add(&terminal_row);
|
||||
program.add(&hint);
|
||||
let page = adw::PreferencesPage::new();
|
||||
page.add(&group);
|
||||
page.add(&files);
|
||||
page.add(&program);
|
||||
|
||||
let cancel = gtk4::Button::with_label(&gettext("Cancel"));
|
||||
let save_button = gtk4::Button::with_label(&gettext("Save"));
|
||||
save_button.add_css_class("suggested-action");
|
||||
let header = adw::HeaderBar::builder()
|
||||
.show_start_title_buttons(false)
|
||||
.show_end_title_buttons(false)
|
||||
.build();
|
||||
header.pack_start(&cancel);
|
||||
header.pack_end(&save_button);
|
||||
let view = adw::ToolbarView::new();
|
||||
view.add_top_bar(&header);
|
||||
view.set_content(Some(&page));
|
||||
let dialog = adw::Dialog::builder()
|
||||
.title(if index.is_some() {
|
||||
gettext("Edit Rule")
|
||||
} else {
|
||||
gettext("New Rule")
|
||||
})
|
||||
.content_width(480)
|
||||
.child(&view)
|
||||
.build();
|
||||
|
||||
// Save only a rule that matches something and runs something.
|
||||
let check = {
|
||||
let (patterns_row, command_row, save_button, hint) = (
|
||||
patterns_row.clone(),
|
||||
command_row.clone(),
|
||||
save_button.clone(),
|
||||
hint.clone(),
|
||||
);
|
||||
move || {
|
||||
let patterns = split_patterns(&patterns_row.text());
|
||||
let argv = parse_command(&command_row.text());
|
||||
command_row.remove_css_class("error");
|
||||
hint.set_text("");
|
||||
match &argv {
|
||||
None => {
|
||||
command_row.add_css_class("error");
|
||||
hint.set_text(&gettext("A quote is not closed in the command."));
|
||||
}
|
||||
Some(argv) if !argv.is_empty() && !command_available(argv) => {
|
||||
hint.set_text(&gettext_f(
|
||||
"“{program}” isn't installed.",
|
||||
&[("program", &argv[0])],
|
||||
));
|
||||
}
|
||||
Some(_) => {}
|
||||
}
|
||||
save_button
|
||||
.set_sensitive(!patterns.is_empty() && argv.is_some_and(|argv| !argv.is_empty()));
|
||||
}
|
||||
};
|
||||
check();
|
||||
let c = check.clone();
|
||||
patterns_row.connect_changed(move |_| c());
|
||||
command_row.connect_changed(move |_| check());
|
||||
|
||||
let d = dialog.clone();
|
||||
cancel.connect_clicked(move |_| {
|
||||
d.close();
|
||||
});
|
||||
let (a, d) = (apps.clone(), dialog.clone());
|
||||
save_button.connect_clicked(move |_| {
|
||||
let Some(command) = parse_command(&command_row.text()) else {
|
||||
return;
|
||||
};
|
||||
let rule = OpenRule {
|
||||
patterns: split_patterns(&patterns_row.text()),
|
||||
command,
|
||||
terminal: terminal_row.is_active(),
|
||||
};
|
||||
let saved = save(&a, move |config| {
|
||||
let rules = &mut open_with_of(config).rules;
|
||||
match index {
|
||||
Some(i) if i < rules.len() => rules[i] = rule,
|
||||
_ => rules.push(rule),
|
||||
}
|
||||
});
|
||||
if saved {
|
||||
d.close();
|
||||
}
|
||||
});
|
||||
dialog.present(Some(&apps.ui.status.prefs));
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn typed_patterns_are_split_on_commas() {
|
||||
assert_eq!(
|
||||
split_patterns(" *.md, @text ,, notes-*.txt "),
|
||||
["*.md", "@text", "notes-*.txt"]
|
||||
);
|
||||
assert!(split_patterns(" , ").is_empty());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,346 @@
|
||||
//! Preferences → Sync: the patterns every synced folder leaves out
|
||||
//! (`ignore_patterns`) and what the conflict sweep may do (`conflict_sweep`).
|
||||
//!
|
||||
//! Both live in `config.json`. The daemon reads the patterns again on every
|
||||
//! sync pass, so a change here is followed by a Sync Now and applies at once;
|
||||
//! the sweep mode is read when the service starts, so a change offers a
|
||||
//! restart, as the mountpoint does.
|
||||
|
||||
use crate::*;
|
||||
use pdfs_core::config::SweepMode;
|
||||
use pdfs_core::syncignore::{DEFAULT_IGNORE_PATTERNS, check_pattern};
|
||||
|
||||
/// The widgets of the Sync page, built with the rest of the dialog and wired
|
||||
/// once the app's state exists.
|
||||
pub(crate) struct SyncPrefs {
|
||||
pub(crate) page: adw::PreferencesPage,
|
||||
patterns: adw::PreferencesGroup,
|
||||
add_row: adw::EntryRow,
|
||||
reset: gtk4::Button,
|
||||
sweep_row: adw::ComboRow,
|
||||
/// Whether the built-in patterns are shown, kept across repaints.
|
||||
builtin_expanded: Cell<bool>,
|
||||
}
|
||||
|
||||
/// The sweep modes in the order the combo row lists them.
|
||||
const SWEEP_MODES: [SweepMode; 3] = [SweepMode::Report, SweepMode::Enforce, SweepMode::Off];
|
||||
|
||||
pub(crate) fn build_sync_prefs() -> SyncPrefs {
|
||||
let reset = gtk4::Button::builder()
|
||||
.label(gettext("Reset"))
|
||||
.tooltip_text(gettext("Use the built-in patterns again"))
|
||||
.valign(gtk4::Align::Center)
|
||||
.build();
|
||||
reset.add_css_class("flat");
|
||||
let patterns = adw::PreferencesGroup::builder()
|
||||
.title(gettext("Excluded Files"))
|
||||
.description(gettext(
|
||||
"Files and folders matching these patterns are not synced in any synced folder. Use * for any characters, end a pattern with / to match folders only, and start it with ! to include something again. Excluding never deletes anything from Proton Drive.",
|
||||
))
|
||||
.header_suffix(&reset)
|
||||
.build();
|
||||
let add_row = adw::EntryRow::builder()
|
||||
.title(gettext("Add Pattern"))
|
||||
.show_apply_button(true)
|
||||
.build();
|
||||
add_row.add_css_class("monospace");
|
||||
patterns.add(&add_row);
|
||||
|
||||
let sweep_row = adw::ComboRow::builder()
|
||||
.title(gettext("Identical conflict copies"))
|
||||
.subtitle(gettext(
|
||||
"A copy made when a file changed in two places, found to be the same as the file",
|
||||
))
|
||||
.model(>k4::StringList::new(&[
|
||||
&gettext("Report Only"),
|
||||
&gettext("Move to Trash"),
|
||||
&gettext("Off"),
|
||||
]))
|
||||
.build();
|
||||
let conflicts = adw::PreferencesGroup::builder()
|
||||
.title(gettext("Conflict Copies"))
|
||||
.build();
|
||||
conflicts.add(&sweep_row);
|
||||
|
||||
let page = adw::PreferencesPage::builder()
|
||||
.title(gettext("Sync"))
|
||||
.name("sync")
|
||||
.icon_name("pdfs-sync-symbolic")
|
||||
.build();
|
||||
page.add(&patterns);
|
||||
page.add(&conflicts);
|
||||
SyncPrefs {
|
||||
page,
|
||||
patterns,
|
||||
add_row,
|
||||
reset,
|
||||
sweep_row,
|
||||
builtin_expanded: Cell::new(false),
|
||||
}
|
||||
}
|
||||
|
||||
/// Fill the page from the config and connect its controls.
|
||||
pub(crate) fn wire_sync_prefs(ui: &Rc<Ui>, widgets: SyncPrefs) {
|
||||
let widgets = Rc::new(widgets);
|
||||
let rows: Rc<RefCell<Vec<adw::PreferencesRow>>> = Rc::default();
|
||||
let config = ui.dirs.load_config();
|
||||
paint_patterns(ui, &widgets, &rows, &config);
|
||||
// The Sync page and `pdfs sync ignore` change the patterns too: show the
|
||||
// saved ones each time the page comes up.
|
||||
let (ui_map, w_map, rows_map) = (ui.clone(), widgets.clone(), rows.clone());
|
||||
widgets.page.connect_map(move |_| {
|
||||
let config = ui_map.dirs.load_config();
|
||||
paint_patterns(&ui_map, &w_map, &rows_map, &config);
|
||||
});
|
||||
|
||||
let mode = config.conflict_sweep.unwrap_or_default();
|
||||
let suppress = ui.status.settings_suppress.replace(true);
|
||||
widgets.sweep_row.set_selected(
|
||||
SWEEP_MODES
|
||||
.iter()
|
||||
.position(|m| *m == mode)
|
||||
.unwrap_or_default() as u32,
|
||||
);
|
||||
ui.status.settings_suppress.set(suppress);
|
||||
|
||||
widgets.add_row.connect_changed(|row| {
|
||||
let text = row.text();
|
||||
if text.trim().is_empty() || check_pattern(text.trim()).is_ok() {
|
||||
row.remove_css_class("error");
|
||||
} else {
|
||||
row.add_css_class("error");
|
||||
}
|
||||
});
|
||||
let (ui_add, w_add, rows_add) = (ui.clone(), widgets.clone(), rows.clone());
|
||||
widgets.add_row.connect_apply(move |row| {
|
||||
let pattern = row.text().trim().to_string();
|
||||
if pattern.is_empty() {
|
||||
return;
|
||||
}
|
||||
if let Err(e) = check_pattern(&pattern) {
|
||||
tracing::debug!(%pattern, error = %e, "not a valid ignore pattern");
|
||||
prefs_toast(
|
||||
&ui_add,
|
||||
// Translators: {pattern} is what the user typed as a pattern.
|
||||
&gettext_f(
|
||||
"“{pattern}” isn't a valid pattern",
|
||||
&[("pattern", &pattern)],
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
let added = change_patterns(&ui_add, &w_add, &rows_add, |list| {
|
||||
if !list.contains(&pattern) {
|
||||
list.push(pattern.clone());
|
||||
}
|
||||
});
|
||||
if added {
|
||||
row.set_text("");
|
||||
}
|
||||
});
|
||||
|
||||
let (ui_reset, w_reset, rows_reset) = (ui.clone(), widgets.clone(), rows.clone());
|
||||
widgets.reset.connect_clicked(move |_| {
|
||||
let (ui, w, rows) = (ui_reset.clone(), w_reset.clone(), rows_reset.clone());
|
||||
confirm_destructive(
|
||||
&ui_reset.status.prefs,
|
||||
&gettext("Reset Excluded Files?"),
|
||||
&gettext("Your own patterns are removed, and the built-in ones apply again."),
|
||||
&gettext("Reset"),
|
||||
move || {
|
||||
change_patterns(&ui, &w, &rows, |list| {
|
||||
*list = default_patterns();
|
||||
});
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
let ui_sweep = ui.clone();
|
||||
widgets.sweep_row.connect_selected_notify(move |row| {
|
||||
if ui_sweep.status.settings_suppress.get() {
|
||||
return;
|
||||
}
|
||||
let Some(mode) = SWEEP_MODES.get(row.selected() as usize).copied() else {
|
||||
return;
|
||||
};
|
||||
let stored = (mode != SweepMode::default()).then_some(mode);
|
||||
match ui_sweep
|
||||
.dirs
|
||||
.update_config(|config| config.conflict_sweep = stored)
|
||||
{
|
||||
Ok(()) => offer_restart(&ui_sweep),
|
||||
Err(e) => prefs_toast(
|
||||
&ui_sweep,
|
||||
&gettext_f(
|
||||
"{what}: {detail}",
|
||||
&[
|
||||
("what", &gettext("Couldn't save the setting")),
|
||||
("detail", &e.to_string()),
|
||||
],
|
||||
),
|
||||
),
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fn default_patterns() -> Vec<String> {
|
||||
DEFAULT_IGNORE_PATTERNS
|
||||
.iter()
|
||||
.map(|p| (*p).to_string())
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Apply `edit` to the patterns in effect and save them, then show them and
|
||||
/// have every synced folder sync with them. Says whether it saved.
|
||||
fn change_patterns(
|
||||
ui: &Rc<Ui>,
|
||||
widgets: &Rc<SyncPrefs>,
|
||||
rows: &Rc<RefCell<Vec<adw::PreferencesRow>>>,
|
||||
edit: impl FnOnce(&mut Vec<String>),
|
||||
) -> bool {
|
||||
match ui.dirs.change_ignore_patterns(edit) {
|
||||
Ok(config) => {
|
||||
paint_patterns(ui, widgets, rows, &config);
|
||||
// Best effort: the next pass picks the change up anyway.
|
||||
let _ = spawn_request(ui.dirs.control_socket(), Request::SyncNow { id: None });
|
||||
true
|
||||
}
|
||||
Err(e) => {
|
||||
prefs_toast(
|
||||
ui,
|
||||
&gettext_f(
|
||||
"{what}: {detail}",
|
||||
&[
|
||||
("what", &gettext("Couldn't save the patterns")),
|
||||
("detail", &e.to_string()),
|
||||
],
|
||||
),
|
||||
);
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Show the patterns in effect below the entry row: the user's own one row
|
||||
/// each, then the built-in ones folded into one row, since they are many and
|
||||
/// rarely changed.
|
||||
fn paint_patterns(
|
||||
ui: &Rc<Ui>,
|
||||
widgets: &Rc<SyncPrefs>,
|
||||
rows: &Rc<RefCell<Vec<adw::PreferencesRow>>>,
|
||||
config: &pdfs_core::config::AppConfig,
|
||||
) {
|
||||
for row in rows.borrow_mut().drain(..) {
|
||||
widgets.patterns.remove(&row);
|
||||
}
|
||||
widgets
|
||||
.reset
|
||||
.set_sensitive(config.ignore_patterns.is_some());
|
||||
let list = config.resolved_ignore_patterns();
|
||||
let (builtin, own): (Vec<String>, Vec<String>) = list
|
||||
.into_iter()
|
||||
.partition(|p| DEFAULT_IGNORE_PATTERNS.contains(&p.as_str()));
|
||||
for pattern in own {
|
||||
let row = pattern_row(ui, widgets, rows, pattern);
|
||||
widgets.patterns.add(&row);
|
||||
rows.borrow_mut().push(row.upcast());
|
||||
}
|
||||
// Every built-in pattern, on or off, so one turned off can be turned on
|
||||
// again without losing the user's own.
|
||||
let on = builtin.len();
|
||||
let total = DEFAULT_IGNORE_PATTERNS.len();
|
||||
let expander = adw::ExpanderRow::builder()
|
||||
.title(gettext("Built-in patterns"))
|
||||
// Translators: {on} and {total} are numbers of patterns.
|
||||
.subtitle(gettext_f(
|
||||
"{on} of {total} on: version control, dependency and build folders, and what editors, downloads and systems leave behind",
|
||||
&[("on", &on.to_string()), ("total", &total.to_string())],
|
||||
))
|
||||
.expanded(widgets.builtin_expanded.get())
|
||||
.build();
|
||||
let w = widgets.clone();
|
||||
expander.connect_expanded_notify(move |row| w.builtin_expanded.set(row.is_expanded()));
|
||||
for pattern in DEFAULT_IGNORE_PATTERNS {
|
||||
let row = adw::SwitchRow::builder()
|
||||
.title(format!("<tt>{}</tt>", glib::markup_escape_text(pattern)))
|
||||
.use_markup(true)
|
||||
.active(builtin.iter().any(|p| p == pattern))
|
||||
.build();
|
||||
let (ui, w, r) = (ui.clone(), widgets.clone(), rows.clone());
|
||||
row.connect_active_notify(move |row| {
|
||||
let active = row.is_active();
|
||||
// Repainting replaces this row; let the switch finish first.
|
||||
let (ui, w, r) = (ui.clone(), w.clone(), r.clone());
|
||||
glib::idle_add_local_once(move || {
|
||||
change_patterns(&ui, &w, &r, move |list| {
|
||||
list.retain(|p| p != pattern);
|
||||
if active {
|
||||
list.push((*pattern).to_string());
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
expander.add_row(&row);
|
||||
}
|
||||
widgets.patterns.add(&expander);
|
||||
rows.borrow_mut().push(expander.upcast());
|
||||
}
|
||||
|
||||
/// One pattern, in monospace, with a button that removes it.
|
||||
fn pattern_row(
|
||||
ui: &Rc<Ui>,
|
||||
widgets: &Rc<SyncPrefs>,
|
||||
rows: &Rc<RefCell<Vec<adw::PreferencesRow>>>,
|
||||
pattern: String,
|
||||
) -> adw::ActionRow {
|
||||
let row = adw::ActionRow::builder()
|
||||
.title(format!("<tt>{}</tt>", glib::markup_escape_text(&pattern)))
|
||||
.use_markup(true)
|
||||
.build();
|
||||
let remove = gtk4::Button::builder()
|
||||
.icon_name("user-trash-symbolic")
|
||||
.tooltip_text(gettext("Remove"))
|
||||
.valign(gtk4::Align::Center)
|
||||
.build();
|
||||
remove.add_css_class("flat");
|
||||
let (ui, w, r) = (ui.clone(), widgets.clone(), rows.clone());
|
||||
remove.connect_clicked(move |_| {
|
||||
let pattern = pattern.clone();
|
||||
change_patterns(&ui, &w, &r, move |list| list.retain(|p| *p != pattern));
|
||||
});
|
||||
row.add_suffix(&remove);
|
||||
row
|
||||
}
|
||||
|
||||
/// The sweep mode is read when the service starts; offer that restart.
|
||||
fn offer_restart(ui: &Rc<Ui>) {
|
||||
let confirm = adw::AlertDialog::builder()
|
||||
.heading(gettext("Restart Proton Drive?"))
|
||||
.body(gettext(
|
||||
"The new setting applies after Proton Drive restarts.",
|
||||
))
|
||||
.build();
|
||||
confirm.add_response("later", &gettext("Later"));
|
||||
confirm.add_response("restart", &gettext("Restart Now"));
|
||||
confirm.set_response_appearance("restart", adw::ResponseAppearance::Suggested);
|
||||
confirm.set_default_response(Some("restart"));
|
||||
confirm.set_close_response("later");
|
||||
let ui_restart = ui.clone();
|
||||
confirm.connect_response(None, move |_, resp| {
|
||||
if resp == "restart" {
|
||||
restart_service_then(&ui_restart, |_| {});
|
||||
}
|
||||
});
|
||||
confirm.present(Some(&ui.status.prefs));
|
||||
}
|
||||
|
||||
/// A toast on the Preferences dialog, which covers the window's own toasts.
|
||||
pub(crate) fn prefs_toast(ui: &Rc<Ui>, message: &str) {
|
||||
ui.status.prefs.add_toast(
|
||||
adw::Toast::builder()
|
||||
.title(message)
|
||||
.use_markup(false)
|
||||
.timeout(6)
|
||||
.build(),
|
||||
);
|
||||
}
|
||||
@@ -169,6 +169,9 @@ pub(crate) struct MainWidgets {
|
||||
pub(crate) tray_row: adw::SwitchRow,
|
||||
pub(crate) update_row: adw::SwitchRow,
|
||||
pub(crate) language_row: adw::ComboRow,
|
||||
/// Preferences → Sync and → Apps, wired once the app's state exists.
|
||||
pub(crate) sync_prefs: SyncPrefs,
|
||||
pub(crate) apps_prefs: AppsPrefs,
|
||||
}
|
||||
|
||||
/// Build the two surfaces that replaced the old Settings page:
|
||||
@@ -267,6 +270,7 @@ pub(crate) fn build_main_page() -> MainWidgets {
|
||||
|
||||
let general = adw::PreferencesPage::builder()
|
||||
.title(gettext("General"))
|
||||
.name("general")
|
||||
.icon_name("preferences-system-symbolic")
|
||||
.build();
|
||||
general.add(&startup_group);
|
||||
@@ -335,6 +339,7 @@ pub(crate) fn build_main_page() -> MainWidgets {
|
||||
|
||||
let storage = adw::PreferencesPage::builder()
|
||||
.title(gettext("Storage"))
|
||||
.name("storage")
|
||||
.icon_name("drive-harddisk-symbolic")
|
||||
.build();
|
||||
storage.add(&storage_group);
|
||||
@@ -343,7 +348,11 @@ pub(crate) fn build_main_page() -> MainWidgets {
|
||||
let prefs = adw::PreferencesDialog::builder()
|
||||
.search_enabled(false)
|
||||
.build();
|
||||
let sync_prefs = build_sync_prefs();
|
||||
let apps_prefs = build_apps_prefs();
|
||||
prefs.add(&general);
|
||||
prefs.add(&sync_prefs.page);
|
||||
prefs.add(&apps_prefs.page);
|
||||
prefs.add(&storage);
|
||||
|
||||
// ---- Sidebar footer
|
||||
@@ -463,6 +472,8 @@ pub(crate) fn build_main_page() -> MainWidgets {
|
||||
tray_row,
|
||||
update_row,
|
||||
language_row,
|
||||
sync_prefs,
|
||||
apps_prefs,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -678,9 +689,10 @@ pub(crate) fn wire_settings(
|
||||
let rows = list.model.n_items();
|
||||
list.model.items_changed(0, rows, rows);
|
||||
}
|
||||
let mut config = ui_theme.dirs.load_config();
|
||||
config.proton_theme = Some(on);
|
||||
if let Err(e) = ui_theme.dirs.save_config(&config) {
|
||||
if let Err(e) = ui_theme
|
||||
.dirs
|
||||
.update_config(|config| config.proton_theme = Some(on))
|
||||
{
|
||||
toast_error(
|
||||
&ui_theme,
|
||||
&gettext("Couldn't save the theme"),
|
||||
@@ -700,9 +712,7 @@ pub(crate) fn wire_settings(
|
||||
.gallery
|
||||
.places_map
|
||||
.set_online(on, ui_map.dirs.cache_dir());
|
||||
let mut config = ui_map.dirs.load_config();
|
||||
config.online_map = on;
|
||||
if let Err(e) = ui_map.dirs.save_config(&config) {
|
||||
if let Err(e) = ui_map.dirs.update_config(|config| config.online_map = on) {
|
||||
toast_error(
|
||||
&ui_map,
|
||||
&gettext("Couldn't save the map setting"),
|
||||
@@ -717,9 +727,10 @@ pub(crate) fn wire_settings(
|
||||
if ui_update.status.settings_suppress.get() {
|
||||
return;
|
||||
}
|
||||
let mut config = ui_update.dirs.load_config();
|
||||
config.update_check = row.is_active();
|
||||
if let Err(e) = ui_update.dirs.save_config(&config) {
|
||||
if let Err(e) = ui_update
|
||||
.dirs
|
||||
.update_config(|config| config.update_check = row.is_active())
|
||||
{
|
||||
toast_error(
|
||||
&ui_update,
|
||||
&gettext("Couldn't save the update setting"),
|
||||
@@ -739,9 +750,10 @@ pub(crate) fn wire_settings(
|
||||
return;
|
||||
}
|
||||
let show = row.is_active();
|
||||
let mut config = ui_tray.dirs.load_config();
|
||||
config.tray_hidden = !show;
|
||||
if let Err(e) = ui_tray.dirs.save_config(&config) {
|
||||
if let Err(e) = ui_tray
|
||||
.dirs
|
||||
.update_config(|config| config.tray_hidden = !show)
|
||||
{
|
||||
toast_error(
|
||||
&ui_tray,
|
||||
&gettext("Couldn't save the tray setting"),
|
||||
@@ -763,9 +775,9 @@ pub(crate) fn wire_settings(
|
||||
if ui_language.status.settings_suppress.get() {
|
||||
return;
|
||||
}
|
||||
let mut config = ui_language.dirs.load_config();
|
||||
config.language = language_at(row.selected()).map(str::to_string);
|
||||
if let Err(e) = ui_language.dirs.save_config(&config) {
|
||||
if let Err(e) = ui_language.dirs.update_config(|config| {
|
||||
config.language = language_at(row.selected()).map(str::to_string)
|
||||
}) {
|
||||
toast_error(
|
||||
&ui_language,
|
||||
&gettext("Couldn't save the language"),
|
||||
@@ -864,9 +876,10 @@ fn use_mountpoint(ui: &Rc<Ui>, path: &std::path::Path) {
|
||||
let path_str = path.display().to_string();
|
||||
|
||||
// Persist the choice to config so the next mount uses it.
|
||||
let mut config = ui.dirs.load_config();
|
||||
config.mountpoint = Some(path_str.clone());
|
||||
if let Err(e) = ui.dirs.save_config(&config) {
|
||||
if let Err(e) = ui
|
||||
.dirs
|
||||
.update_config(|config| config.mountpoint = Some(path_str.clone()))
|
||||
{
|
||||
toast_error(ui, &gettext("Couldn't save the folder"), &e.to_string());
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,426 @@
|
||||
//! The Excluded Files group on the Sync page's Folders view: what is left out
|
||||
//! of every synced folder and of each one on its own, with how many patterns
|
||||
//! each has, and an Add Pattern dialog that asks where a pattern goes.
|
||||
//!
|
||||
//! The rows open the editors that already exist: Preferences → Sync for the
|
||||
//! patterns of all folders, the Excluded Files dialog for a folder's own
|
||||
//! `.pdfsignore`. Only folders kept on this computer are listed; an
|
||||
//! online-only folder has no local files for patterns to leave out. With none
|
||||
//! of those, the group still shows, so the patterns can be found and set up
|
||||
//! before a folder is switched to Synced, and says why they do nothing yet.
|
||||
|
||||
use crate::*;
|
||||
use pdfs_core::syncignore::{FolderRules, add_folder_pattern, check_pattern};
|
||||
|
||||
pub(crate) struct ExclusionsState {
|
||||
pub(crate) group: adw::PreferencesGroup,
|
||||
pub(crate) add: gtk4::Button,
|
||||
pub(crate) rows: RefCell<Vec<adw::ActionRow>>,
|
||||
/// The synced folders kept on this computer the rows were built for, as
|
||||
/// id and root.
|
||||
pub(crate) folders: RefCell<Vec<(i64, PathBuf)>>,
|
||||
/// Counts painted, so a slow read from an older paint does not land on
|
||||
/// newer rows.
|
||||
pub(crate) generation: Cell<u64>,
|
||||
}
|
||||
|
||||
pub(crate) fn build_exclusions_group() -> (adw::PreferencesGroup, gtk4::Button) {
|
||||
let add = gtk4::Button::builder()
|
||||
.child(
|
||||
&adw::ButtonContent::builder()
|
||||
.label(gettext("Add Pattern"))
|
||||
.icon_name("list-add-symbolic")
|
||||
.build(),
|
||||
)
|
||||
.tooltip_text(gettext(
|
||||
"Leave files matching a pattern out of all synced folders or one of them",
|
||||
))
|
||||
.valign(gtk4::Align::Center)
|
||||
.build();
|
||||
add.add_css_class("flat");
|
||||
let group = adw::PreferencesGroup::builder()
|
||||
.title(gettext("Excluded Files"))
|
||||
.description(gettext(
|
||||
"Files matching these patterns stay on this computer and are not synced. Excluding never deletes anything from Proton Drive.",
|
||||
))
|
||||
.header_suffix(&add)
|
||||
.visible(false)
|
||||
.build();
|
||||
(group, add)
|
||||
}
|
||||
|
||||
pub(crate) fn wire_exclusions(ui: &Rc<Ui>) {
|
||||
let ui_add = ui.clone();
|
||||
ui.locations
|
||||
.exclusions
|
||||
.add
|
||||
.connect_clicked(move |_| present_add_pattern_dialog(&ui_add, None));
|
||||
// Preferences change the patterns of all folders; show the new count.
|
||||
let ui_prefs = ui.clone();
|
||||
ui.status
|
||||
.prefs
|
||||
.connect_closed(move |_| refresh_exclusions(&ui_prefs));
|
||||
}
|
||||
|
||||
/// Rebuild the rows for the folders in `items` when the set of synced folders
|
||||
/// kept on this computer changed, or on the first paint. The tick repaints the folder list every few
|
||||
/// seconds; the rows and their counts stay as they are in between.
|
||||
pub(crate) fn paint_exclusions(ui: &Rc<Ui>, items: &[MountSpec]) {
|
||||
let folders: Vec<(i64, PathBuf)> = items
|
||||
.iter()
|
||||
.filter(|spec| spec.mode == MountMode::Mirror)
|
||||
.filter_map(|spec| match spec.kind {
|
||||
MountKind::Device { sync_folder_id } | MountKind::Attached { sync_folder_id } => {
|
||||
Some((sync_folder_id, PathBuf::from(&spec.local_path)))
|
||||
}
|
||||
_ => None,
|
||||
})
|
||||
.collect();
|
||||
let state = &ui.locations.exclusions;
|
||||
if *state.folders.borrow() == folders && !state.rows.borrow().is_empty() {
|
||||
return;
|
||||
}
|
||||
*state.folders.borrow_mut() = folders;
|
||||
refresh_exclusions(ui);
|
||||
}
|
||||
|
||||
/// Build the rows again from the folders last painted, and read every count
|
||||
/// anew: after a pattern was added or a list edited.
|
||||
pub(crate) fn refresh_exclusions(ui: &Rc<Ui>) {
|
||||
let state = &ui.locations.exclusions;
|
||||
for row in state.rows.borrow_mut().drain(..) {
|
||||
state.group.remove(&row);
|
||||
}
|
||||
let folders = state.folders.borrow().clone();
|
||||
state.group.set_visible(true);
|
||||
let generation = state.generation.get() + 1;
|
||||
state.generation.set(generation);
|
||||
|
||||
let config = ui.dirs.load_config();
|
||||
let all = adw::ActionRow::builder()
|
||||
.title(gettext("All Synced Folders"))
|
||||
.subtitle(glib::markup_escape_text(&all_folders_subtitle(&config)).as_str())
|
||||
.activatable(true)
|
||||
.build();
|
||||
all.add_prefix(>k4::Image::from_icon_name("view-list-symbolic"));
|
||||
all.add_suffix(>k4::Image::from_icon_name("go-next-symbolic"));
|
||||
let ui_all = ui.clone();
|
||||
all.connect_activated(move |_| {
|
||||
let prefs = &ui_all.status.prefs;
|
||||
prefs.set_visible_page_name("sync");
|
||||
prefs.present(ui_window(&ui_all).as_ref());
|
||||
});
|
||||
state.group.add(&all);
|
||||
let mut rows = vec![all];
|
||||
if folders.is_empty() {
|
||||
let none = adw::ActionRow::builder()
|
||||
.title(gettext("No folder is set to Synced"))
|
||||
.subtitle(gettext(
|
||||
"Patterns apply only to folders kept on this computer. Online-only folders upload every file saved in them.",
|
||||
))
|
||||
.build();
|
||||
none.add_prefix(>k4::Image::from_icon_name("info-outline-symbolic"));
|
||||
state.group.add(&none);
|
||||
rows.push(none);
|
||||
}
|
||||
|
||||
let mut counted = Vec::new();
|
||||
for (id, root) in folders {
|
||||
let name = root
|
||||
.file_name()
|
||||
.map(|name| name.to_string_lossy().into_owned())
|
||||
.unwrap_or_else(|| root.display().to_string());
|
||||
let row = adw::ActionRow::builder()
|
||||
.title(glib::markup_escape_text(&name).as_str())
|
||||
.tooltip_text(root.display().to_string())
|
||||
.subtitle(glib::markup_escape_text(&tilde_path(&root.display().to_string())).as_str())
|
||||
.subtitle_lines(1)
|
||||
.activatable(true)
|
||||
.build();
|
||||
row.add_prefix(>k4::Image::from_icon_name("folder-symbolic"));
|
||||
row.add_suffix(>k4::Image::from_icon_name("go-next-symbolic"));
|
||||
let (ui_row, root_row) = (ui.clone(), root.clone());
|
||||
row.connect_activated(move |_| present_ignore_dialog(&ui_row, id, root_row.clone()));
|
||||
state.group.add(&row);
|
||||
counted.push((row.clone(), root));
|
||||
rows.push(row);
|
||||
}
|
||||
*state.rows.borrow_mut() = rows;
|
||||
|
||||
// A folder may sit on a slow or sleeping disk: count off the main thread.
|
||||
let ui = ui.clone();
|
||||
glib::spawn_future_local(async move {
|
||||
let roots: Vec<PathBuf> = counted.iter().map(|(_, root)| root.clone()).collect();
|
||||
let counts = gio::spawn_blocking(move || {
|
||||
roots
|
||||
.iter()
|
||||
.map(|root| {
|
||||
FolderRules::read(root)
|
||||
.ok()
|
||||
.map(|rules| rules.patterns().len())
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
})
|
||||
.await
|
||||
.unwrap_or_default();
|
||||
if ui.locations.exclusions.generation.get() != generation {
|
||||
return;
|
||||
}
|
||||
for ((row, root), count) in counted.iter().zip(counts) {
|
||||
let state = match count {
|
||||
Some(0) => gettext("no own patterns"),
|
||||
// Translators: how many patterns a synced folder has of its own.
|
||||
Some(n) => ngettext_f("{n} own pattern", "{n} own patterns", n as u64, &[]),
|
||||
None => gettext("own patterns unreadable"),
|
||||
};
|
||||
// Translators: a synced folder's location and how many patterns of its own it has, such as "~/Projects · 2 own patterns".
|
||||
let subtitle = gettext_f(
|
||||
"{path} · {state}",
|
||||
&[
|
||||
("path", &tilde_path(&root.display().to_string())),
|
||||
("state", &state),
|
||||
],
|
||||
);
|
||||
row.set_subtitle(glib::markup_escape_text(&subtitle).as_str());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// How many patterns apply to every synced folder, and whether they are the
|
||||
/// built-in ones.
|
||||
fn all_folders_subtitle(config: &pdfs_core::config::AppConfig) -> String {
|
||||
let n = config.resolved_ignore_patterns().len() as u64;
|
||||
match (&config.ignore_patterns, n) {
|
||||
(_, 0) => gettext("No patterns: every file is synced"),
|
||||
(None, n) => ngettext_f("{n} built-in pattern", "{n} built-in patterns", n, &[]),
|
||||
(Some(_), n) => ngettext_f("{n} pattern", "{n} patterns", n, &[]),
|
||||
}
|
||||
}
|
||||
|
||||
/// Ask for a pattern and where it applies: every synced folder, or one of
|
||||
/// them (`folder`, preselected when given).
|
||||
pub(crate) fn present_add_pattern_dialog(ui: &Rc<Ui>, folder: Option<i64>) {
|
||||
let folders = ui.locations.exclusions.folders.borrow().clone();
|
||||
let pattern_row = adw::EntryRow::builder().title(gettext("Pattern")).build();
|
||||
pattern_row.add_css_class("monospace");
|
||||
let mut places = vec![gettext("All synced folders")];
|
||||
places.extend(
|
||||
folders
|
||||
.iter()
|
||||
.map(|(_, root)| tilde_path(&root.display().to_string())),
|
||||
);
|
||||
let places: Vec<&str> = places.iter().map(String::as_str).collect();
|
||||
let scope_row = adw::ComboRow::builder()
|
||||
.title(gettext("Apply To"))
|
||||
.model(>k4::StringList::new(&places))
|
||||
.build();
|
||||
if let Some(at) = folder.and_then(|id| folders.iter().position(|(f, _)| *f == id)) {
|
||||
scope_row.set_selected(at as u32 + 1);
|
||||
}
|
||||
let rows = adw::PreferencesGroup::new();
|
||||
rows.add(&pattern_row);
|
||||
rows.add(&scope_row);
|
||||
|
||||
let hint = gtk4::Label::builder()
|
||||
.label(gettext(
|
||||
"Use * for any characters, such as *.db, and end a pattern with / to match folders only, such as build/.",
|
||||
))
|
||||
.wrap(true)
|
||||
.xalign(0.0)
|
||||
.build();
|
||||
hint.add_css_class("dim-label");
|
||||
hint.add_css_class("caption");
|
||||
let problem = gtk4::Label::builder()
|
||||
.wrap(true)
|
||||
.xalign(0.0)
|
||||
.visible(false)
|
||||
.build();
|
||||
problem.add_css_class("error");
|
||||
|
||||
let body = gtk4::Box::new(gtk4::Orientation::Vertical, 12);
|
||||
body.set_margin_top(12);
|
||||
body.set_margin_bottom(18);
|
||||
body.set_margin_start(18);
|
||||
body.set_margin_end(18);
|
||||
body.append(&rows);
|
||||
body.append(&hint);
|
||||
body.append(&problem);
|
||||
|
||||
let cancel = gtk4::Button::with_label(&gettext("Cancel"));
|
||||
let add = gtk4::Button::with_label(&gettext("Add"));
|
||||
add.add_css_class("suggested-action");
|
||||
add.set_sensitive(false);
|
||||
let header = adw::HeaderBar::builder()
|
||||
.show_start_title_buttons(false)
|
||||
.show_end_title_buttons(false)
|
||||
.build();
|
||||
header.pack_start(&cancel);
|
||||
header.pack_end(&add);
|
||||
let view = adw::ToolbarView::new();
|
||||
view.add_top_bar(&header);
|
||||
view.set_content(Some(&body));
|
||||
let dialog = adw::Dialog::builder()
|
||||
.title(gettext("Add Pattern"))
|
||||
.content_width(460)
|
||||
.child(&view)
|
||||
.build();
|
||||
|
||||
let (add_check, problem_check) = (add.clone(), problem.clone());
|
||||
pattern_row.connect_changed(move |row| {
|
||||
let verdict = pattern_problem(&row.text());
|
||||
match &verdict {
|
||||
Some(message) if !row.text().trim().is_empty() => {
|
||||
row.add_css_class("error");
|
||||
problem_check.set_text(message);
|
||||
problem_check.set_visible(true);
|
||||
}
|
||||
_ => {
|
||||
row.remove_css_class("error");
|
||||
problem_check.set_visible(false);
|
||||
}
|
||||
}
|
||||
add_check.set_sensitive(verdict.is_none());
|
||||
});
|
||||
let d = dialog.clone();
|
||||
cancel.connect_clicked(move |_| {
|
||||
d.close();
|
||||
});
|
||||
|
||||
let submit = {
|
||||
let (ui, dialog, pattern_row, scope_row, add, problem) = (
|
||||
ui.clone(),
|
||||
dialog.clone(),
|
||||
pattern_row.clone(),
|
||||
scope_row.clone(),
|
||||
add.clone(),
|
||||
problem.clone(),
|
||||
);
|
||||
move || {
|
||||
if !add.is_sensitive() {
|
||||
return;
|
||||
}
|
||||
let pattern = pattern_row.text().trim().to_string();
|
||||
let target = match scope_row.selected() {
|
||||
0 => None,
|
||||
at => folders.get(at as usize - 1).cloned(),
|
||||
};
|
||||
// One click, one save: the button comes back if the save fails.
|
||||
add.set_sensitive(false);
|
||||
add_pattern(&ui, &dialog, &add, &problem, pattern, target);
|
||||
}
|
||||
};
|
||||
let submit_enter = submit.clone();
|
||||
pattern_row.connect_entry_activated(move |_| submit_enter());
|
||||
add.connect_clicked(move |_| submit());
|
||||
|
||||
dialog.present(ui_window(ui).as_ref());
|
||||
pattern_row.grab_focus();
|
||||
}
|
||||
|
||||
/// What is wrong with `text` as a pattern to add, or `None` when it is one.
|
||||
fn pattern_problem(text: &str) -> Option<String> {
|
||||
let text = text.trim();
|
||||
if text.is_empty() {
|
||||
return Some(String::new());
|
||||
}
|
||||
if text.starts_with('#') {
|
||||
return Some(gettext(
|
||||
"A line starting with # is a comment, not a pattern.",
|
||||
));
|
||||
}
|
||||
check_pattern(text).err().map(|e| {
|
||||
tracing::debug!(pattern = %text, error = %e, "not a valid ignore pattern");
|
||||
// Translators: {pattern} is what the user typed as a pattern.
|
||||
gettext_f("“{pattern}” isn't a valid pattern.", &[("pattern", text)])
|
||||
})
|
||||
}
|
||||
|
||||
/// Save `pattern` for every synced folder (`target` is `None`) or for the
|
||||
/// folder `target`, then close `dialog`, say so and sync. A failure shows in
|
||||
/// `problem`, in the dialog, which stays open.
|
||||
fn add_pattern(
|
||||
ui: &Rc<Ui>,
|
||||
dialog: &adw::Dialog,
|
||||
add: >k4::Button,
|
||||
problem: >k4::Label,
|
||||
pattern: String,
|
||||
target: Option<(i64, PathBuf)>,
|
||||
) {
|
||||
let (ui, dialog, add, problem) = (ui.clone(), dialog.clone(), add.clone(), problem.clone());
|
||||
glib::spawn_future_local(async move {
|
||||
let (id, place) = match &target {
|
||||
None => (None, gettext("all synced folders")),
|
||||
Some((id, root)) => (Some(*id), tilde_path(&root.display().to_string())),
|
||||
};
|
||||
let added: Result<bool, String> = match target {
|
||||
None => {
|
||||
let mut added = false;
|
||||
ui.dirs
|
||||
.change_ignore_patterns(|list| {
|
||||
if !list.contains(&pattern) {
|
||||
list.push(pattern.clone());
|
||||
added = true;
|
||||
}
|
||||
})
|
||||
.map(|_| added)
|
||||
.map_err(|e| e.to_string())
|
||||
}
|
||||
Some((_, root)) => {
|
||||
let p = pattern.clone();
|
||||
gio::spawn_blocking(move || add_folder_pattern(&root, &p))
|
||||
.await
|
||||
.unwrap_or_else(|_| Err(std::io::Error::other("the save did not finish")))
|
||||
.map_err(|e| e.to_string())
|
||||
}
|
||||
};
|
||||
match added {
|
||||
Ok(added) => {
|
||||
dialog.close();
|
||||
let message = if added {
|
||||
// Translators: {pattern} is an ignore pattern, {place} "all synced folders" or a folder path.
|
||||
gettext_f(
|
||||
"“{pattern}” is now excluded in {place}",
|
||||
&[("pattern", &pattern), ("place", &place)],
|
||||
)
|
||||
} else {
|
||||
gettext_f(
|
||||
"“{pattern}” was already excluded in {place}",
|
||||
&[("pattern", &pattern), ("place", &place)],
|
||||
)
|
||||
};
|
||||
toast(&ui, &message);
|
||||
refresh_exclusions(&ui);
|
||||
if added {
|
||||
// Best effort: the next pass picks the change up anyway.
|
||||
let _ = spawn_request(ui.dirs.control_socket(), Request::SyncNow { id });
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
add.set_sensitive(true);
|
||||
problem.set_text(&gettext_f(
|
||||
"{what}: {detail}",
|
||||
&[
|
||||
("what", &gettext("Couldn't save the patterns")),
|
||||
("detail", &e),
|
||||
],
|
||||
));
|
||||
problem.set_visible(true);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn only_real_patterns_can_be_added() {
|
||||
assert!(pattern_problem("*.db").is_none());
|
||||
assert!(pattern_problem(" build/ ").is_none());
|
||||
assert!(pattern_problem("").is_some());
|
||||
assert!(pattern_problem(" ").is_some());
|
||||
assert!(pattern_problem("# note").is_some());
|
||||
assert!(pattern_problem("*.{jpg,png").is_some());
|
||||
}
|
||||
}
|
||||
@@ -82,10 +82,10 @@ pub(crate) fn start_update_checks(ui: &Rc<Ui>) {
|
||||
match fetch_latest().await {
|
||||
Ok(latest) => {
|
||||
checked = Some(unix_now());
|
||||
let mut config = ui.dirs.load_config();
|
||||
config.update_last_checked = checked;
|
||||
config.update_latest = latest;
|
||||
if let Err(e) = ui.dirs.save_config(&config) {
|
||||
if let Err(e) = ui.dirs.update_config(|config| {
|
||||
config.update_last_checked = checked;
|
||||
config.update_latest = latest;
|
||||
}) {
|
||||
tracing::warn!("update check: cannot save the result: {e}");
|
||||
}
|
||||
show_latest(&ui);
|
||||
|
||||
@@ -0,0 +1,343 @@
|
||||
//! The Excluded Files dialog of one synced folder: its own `.pdfsignore`,
|
||||
//! edited as text, with a check of what the rules do to a path.
|
||||
//!
|
||||
//! The file sits in the synced folder and syncs like any other file, so it can
|
||||
//! change on another computer while it is open here. Saving checks for that
|
||||
//! and asks, rather than writing over the other edit.
|
||||
|
||||
use crate::*;
|
||||
use pdfs_core::syncignore::{FolderRules, IgnoreRules, RuleSource, Verdict, WriteRulesError};
|
||||
|
||||
/// Open the dialog for the synced folder `id` at `root`.
|
||||
pub(crate) fn present_ignore_dialog(ui: &Rc<Ui>, id: i64, root: PathBuf) {
|
||||
let root_display = tilde_path(&root.display().to_string());
|
||||
let intro = gtk4::Label::builder()
|
||||
// Translators: {folder} is a local folder path such as ~/Projects.
|
||||
.label(gettext_f(
|
||||
"Patterns for {folder} only, one per line, on top of the ones for all synced folders. Lines starting with # are comments.",
|
||||
&[("folder", &root_display)],
|
||||
))
|
||||
.wrap(true)
|
||||
.xalign(0.0)
|
||||
.build();
|
||||
let text = gtk4::TextView::builder()
|
||||
.monospace(true)
|
||||
.wrap_mode(gtk4::WrapMode::WordChar)
|
||||
.top_margin(8)
|
||||
.bottom_margin(8)
|
||||
.left_margin(8)
|
||||
.right_margin(8)
|
||||
.sensitive(false)
|
||||
.build();
|
||||
let scroller = gtk4::ScrolledWindow::builder()
|
||||
.child(&text)
|
||||
.min_content_height(180)
|
||||
.vexpand(true)
|
||||
.build();
|
||||
scroller.add_css_class("card");
|
||||
let problems = gtk4::Label::builder()
|
||||
.wrap(true)
|
||||
.xalign(0.0)
|
||||
.visible(false)
|
||||
.build();
|
||||
problems.add_css_class("error");
|
||||
|
||||
let check_row = adw::EntryRow::builder()
|
||||
.title(gettext("Check a path in the folder"))
|
||||
.build();
|
||||
let verdict = gtk4::Label::builder()
|
||||
.wrap(true)
|
||||
.xalign(0.0)
|
||||
.margin_top(6)
|
||||
.build();
|
||||
verdict.add_css_class("dim-label");
|
||||
let check_group = adw::PreferencesGroup::new();
|
||||
check_group.add(&check_row);
|
||||
|
||||
let all_folders = gtk4::Button::builder()
|
||||
.label(gettext("Patterns for All Folders…"))
|
||||
.halign(gtk4::Align::Start)
|
||||
.build();
|
||||
all_folders.add_css_class("flat");
|
||||
|
||||
let body = gtk4::Box::new(gtk4::Orientation::Vertical, 12);
|
||||
body.set_margin_top(12);
|
||||
body.set_margin_bottom(18);
|
||||
body.set_margin_start(18);
|
||||
body.set_margin_end(18);
|
||||
body.append(&intro);
|
||||
body.append(&scroller);
|
||||
body.append(&problems);
|
||||
body.append(&check_group);
|
||||
body.append(&verdict);
|
||||
body.append(&all_folders);
|
||||
|
||||
let cancel = gtk4::Button::with_label(&gettext("Cancel"));
|
||||
let save = gtk4::Button::with_label(&gettext("Save"));
|
||||
save.add_css_class("suggested-action");
|
||||
save.set_sensitive(false);
|
||||
let header = adw::HeaderBar::builder()
|
||||
.show_start_title_buttons(false)
|
||||
.show_end_title_buttons(false)
|
||||
.build();
|
||||
header.pack_start(&cancel);
|
||||
header.pack_end(&save);
|
||||
let toasts = adw::ToastOverlay::new();
|
||||
toasts.set_child(Some(&body));
|
||||
let view = adw::ToolbarView::new();
|
||||
view.add_top_bar(&header);
|
||||
view.set_content(Some(&toasts));
|
||||
let dialog = adw::Dialog::builder()
|
||||
.title(gettext("Excluded Files"))
|
||||
.content_width(560)
|
||||
.content_height(560)
|
||||
.child(&view)
|
||||
.build();
|
||||
|
||||
// What was read, so the save can tell whether the file changed since.
|
||||
let loaded: Rc<RefCell<Option<FolderRules>>> = Rc::default();
|
||||
let globals = Rc::new(ui.dirs.load_config().resolved_ignore_patterns());
|
||||
|
||||
let show_verdict = {
|
||||
let (text, check_row, verdict, root, globals) = (
|
||||
text.clone(),
|
||||
check_row.clone(),
|
||||
verdict.clone(),
|
||||
root.clone(),
|
||||
globals.clone(),
|
||||
);
|
||||
move || {
|
||||
let typed = check_row.text();
|
||||
let typed = typed.trim();
|
||||
if typed.is_empty() {
|
||||
verdict.set_text("");
|
||||
return;
|
||||
}
|
||||
let path = Path::new(typed);
|
||||
let rel = path.strip_prefix(&root).unwrap_or(path);
|
||||
let rel = rel.to_string_lossy();
|
||||
let rel = rel.trim_start_matches('/');
|
||||
let is_dir = typed.ends_with('/') || root.join(rel).is_dir();
|
||||
let rules = IgnoreRules::with_folder_text(&root, &globals, &buffer_text(&text));
|
||||
verdict.set_text(&verdict_text(&rules.explain(rel, is_dir)));
|
||||
}
|
||||
};
|
||||
let on_text = {
|
||||
let (problems, save, show_verdict) = (problems.clone(), save.clone(), show_verdict.clone());
|
||||
move |text: &str| {
|
||||
let bad = pdfs_core::syncignore::check_rules(text);
|
||||
problems.set_visible(!bad.is_empty());
|
||||
if let Some((line, _)) = bad.first() {
|
||||
problems.set_text(&ngettext_f(
|
||||
"Line {line} isn't a valid pattern.",
|
||||
"Line {line} and {more} more aren't valid patterns.",
|
||||
bad.len() as u64,
|
||||
&[
|
||||
("line", &line.to_string()),
|
||||
("more", &(bad.len() - 1).to_string()),
|
||||
],
|
||||
));
|
||||
}
|
||||
save.set_sensitive(bad.is_empty());
|
||||
show_verdict();
|
||||
}
|
||||
};
|
||||
let on_text_changed = on_text.clone();
|
||||
text.buffer()
|
||||
.connect_changed(move |buffer| on_text_changed(&buffer_text_of(buffer)));
|
||||
check_row.connect_changed(move |_| show_verdict());
|
||||
|
||||
let d = dialog.clone();
|
||||
cancel.connect_clicked(move |_| {
|
||||
d.close();
|
||||
});
|
||||
let (ui_all, d) = (ui.clone(), dialog.clone());
|
||||
all_folders.connect_clicked(move |_| {
|
||||
d.close();
|
||||
let prefs = &ui_all.status.prefs;
|
||||
prefs.set_visible_page_name("sync");
|
||||
prefs.present(ui_window(&ui_all).as_ref());
|
||||
});
|
||||
|
||||
// Read off the main thread: the folder may be on a slow disk.
|
||||
let reader = {
|
||||
let (text, loaded, root, toasts) =
|
||||
(text.clone(), loaded.clone(), root.clone(), toasts.clone());
|
||||
move || {
|
||||
let (text, loaded, root, toasts) =
|
||||
(text.clone(), loaded.clone(), root.clone(), toasts.clone());
|
||||
glib::spawn_future_local(async move {
|
||||
let read = gio::spawn_blocking(move || FolderRules::read(&root))
|
||||
.await
|
||||
.unwrap_or_else(|_| Err(std::io::Error::other("the read did not finish")));
|
||||
match read {
|
||||
Ok(rules) => {
|
||||
text.buffer().set_text(rules.text.as_deref().unwrap_or(""));
|
||||
text.set_sensitive(true);
|
||||
*loaded.borrow_mut() = Some(rules);
|
||||
}
|
||||
Err(e) => dialog_toast(
|
||||
&toasts,
|
||||
&gettext_f(
|
||||
"{what}: {detail}",
|
||||
&[
|
||||
("what", &gettext("Couldn't read the patterns")),
|
||||
("detail", &e.to_string()),
|
||||
],
|
||||
),
|
||||
),
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
reader();
|
||||
|
||||
let (ui_save, d) = (ui.clone(), dialog.clone());
|
||||
save.connect_clicked(move |_| {
|
||||
let Some(rules) = loaded.borrow().clone() else {
|
||||
return;
|
||||
};
|
||||
write_rules(
|
||||
&ui_save,
|
||||
&d,
|
||||
&toasts,
|
||||
id,
|
||||
rules,
|
||||
buffer_text(&text),
|
||||
reader.clone(),
|
||||
);
|
||||
});
|
||||
|
||||
dialog.present(ui_window(ui).as_ref());
|
||||
}
|
||||
|
||||
/// Save `body` over `rules`, then close and sync the folder. When the file
|
||||
/// changed since it was read, ask whether to load the other version or to
|
||||
/// replace it; `reload` reads the file into the dialog again.
|
||||
fn write_rules(
|
||||
ui: &Rc<Ui>,
|
||||
dialog: &adw::Dialog,
|
||||
toasts: &adw::ToastOverlay,
|
||||
id: i64,
|
||||
rules: FolderRules,
|
||||
body: String,
|
||||
reload: impl Fn() + Clone + 'static,
|
||||
) {
|
||||
let (ui, dialog, toasts) = (ui.clone(), dialog.clone(), toasts.clone());
|
||||
glib::spawn_future_local(async move {
|
||||
let to_write = rules.clone();
|
||||
let text = body.clone();
|
||||
let written = gio::spawn_blocking(move || to_write.write(&text))
|
||||
.await
|
||||
.unwrap_or_else(|_| {
|
||||
Err(WriteRulesError::Io(std::io::Error::other(
|
||||
"the write did not finish",
|
||||
)))
|
||||
});
|
||||
match written {
|
||||
Ok(()) => {
|
||||
dialog.close();
|
||||
toast(&ui, &gettext("Excluded files saved"));
|
||||
refresh_exclusions(&ui);
|
||||
let _ = spawn_request(ui.dirs.control_socket(), Request::SyncNow { id: Some(id) });
|
||||
}
|
||||
Err(WriteRulesError::Changed) => {
|
||||
let ask = adw::AlertDialog::builder()
|
||||
.heading(gettext("Patterns Changed Elsewhere"))
|
||||
.body(gettext(
|
||||
"The patterns of this folder changed while you edited them, for example on another computer. Load the other version, or replace it with yours?",
|
||||
))
|
||||
.build();
|
||||
ask.add_response("cancel", &gettext("Cancel"));
|
||||
ask.add_response("reload", &gettext("Load Other Version"));
|
||||
ask.add_response("replace", &gettext("Replace"));
|
||||
ask.set_response_appearance("replace", adw::ResponseAppearance::Destructive);
|
||||
ask.set_default_response(Some("cancel"));
|
||||
ask.set_close_response("cancel");
|
||||
let (ui, d, t) = (ui.clone(), dialog.clone(), toasts.clone());
|
||||
ask.connect_response(None, move |_, response| match response {
|
||||
"reload" => reload(),
|
||||
"replace" => {
|
||||
// Read the other version only as the base to check
|
||||
// against, then write over it.
|
||||
let (ui, d, t, body, reload) = (
|
||||
ui.clone(),
|
||||
d.clone(),
|
||||
t.clone(),
|
||||
body.clone(),
|
||||
reload.clone(),
|
||||
);
|
||||
let root = rules.path.parent().map(Path::to_path_buf);
|
||||
glib::spawn_future_local(async move {
|
||||
let Some(root) = root else { return };
|
||||
let read = gio::spawn_blocking(move || FolderRules::read(&root))
|
||||
.await
|
||||
.ok()
|
||||
.and_then(Result::ok);
|
||||
if let Some(current) = read {
|
||||
write_rules(&ui, &d, &t, id, current, body, reload);
|
||||
}
|
||||
});
|
||||
}
|
||||
_ => {}
|
||||
});
|
||||
ask.present(Some(&dialog));
|
||||
}
|
||||
Err(WriteRulesError::Io(e)) => dialog_toast(
|
||||
&toasts,
|
||||
&gettext_f(
|
||||
"{what}: {detail}",
|
||||
&[
|
||||
("what", &gettext("Couldn't save the patterns")),
|
||||
("detail", &e.to_string()),
|
||||
],
|
||||
),
|
||||
),
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// Say what the rules do to the path being checked.
|
||||
fn verdict_text(verdict: &Verdict) -> String {
|
||||
match verdict {
|
||||
Verdict::Synced => gettext("Synced: no pattern matches it."),
|
||||
// Translators: {pattern} is an ignore pattern such as *.log.
|
||||
Verdict::Excluded {
|
||||
pattern,
|
||||
source: RuleSource::ThisFolder,
|
||||
} => gettext_f(
|
||||
"Not synced: excluded by “{pattern}” above.",
|
||||
&[("pattern", pattern)],
|
||||
),
|
||||
Verdict::Excluded {
|
||||
pattern,
|
||||
source: RuleSource::AllFolders,
|
||||
} => gettext_f(
|
||||
"Not synced: excluded by “{pattern}” in the patterns for all folders.",
|
||||
&[("pattern", pattern)],
|
||||
),
|
||||
Verdict::Included { pattern, .. } => gettext_f(
|
||||
"Synced: “{pattern}” includes it again.",
|
||||
&[("pattern", pattern)],
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
fn buffer_text(view: >k4::TextView) -> String {
|
||||
buffer_text_of(&view.buffer())
|
||||
}
|
||||
|
||||
fn buffer_text_of(buffer: >k4::TextBuffer) -> String {
|
||||
let (start, end) = buffer.bounds();
|
||||
buffer.text(&start, &end, false).to_string()
|
||||
}
|
||||
|
||||
fn dialog_toast(toasts: &adw::ToastOverlay, message: &str) {
|
||||
toasts.add_toast(
|
||||
adw::Toast::builder()
|
||||
.title(message)
|
||||
.use_markup(false)
|
||||
.timeout(6)
|
||||
.build(),
|
||||
);
|
||||
}
|
||||
@@ -2,6 +2,7 @@ pub(crate) mod compat;
|
||||
pub(crate) mod crumb;
|
||||
pub(crate) mod details;
|
||||
pub(crate) mod file_list;
|
||||
pub(crate) mod ignore_dialog;
|
||||
pub(crate) mod menu;
|
||||
pub(crate) mod photo_drag;
|
||||
pub(crate) mod player;
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
|
||||
use gettextrs::LocaleCategory;
|
||||
use pdfs_core::config::AppDirs;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
/// The gettext text domain, matching `po/pdfs.pot` and the installed `.mo` name.
|
||||
pub(crate) const DOMAIN: &str = "pdfs";
|
||||
@@ -53,14 +54,11 @@ pub(crate) fn init() {
|
||||
if let Some(code) = language {
|
||||
apply_language(&code);
|
||||
}
|
||||
let dir = std::env::var(LOCALEDIR_ENV)
|
||||
.ok()
|
||||
.filter(|dir| !dir.is_empty())
|
||||
.unwrap_or_else(|| {
|
||||
option_env!("PDFS_LOCALEDIR")
|
||||
.unwrap_or(DEFAULT_LOCALEDIR)
|
||||
.to_string()
|
||||
});
|
||||
let dir = locale_dir(
|
||||
std::env::var(LOCALEDIR_ENV).ok(),
|
||||
option_env!("PDFS_LOCALEDIR"),
|
||||
std::env::current_exe().ok(),
|
||||
);
|
||||
if let Err(e) = gettextrs::bindtextdomain(DOMAIN, dir) {
|
||||
tracing::warn!("bindtextdomain failed: {e}");
|
||||
}
|
||||
@@ -73,6 +71,33 @@ pub(crate) fn init() {
|
||||
}
|
||||
}
|
||||
|
||||
/// Where the catalogs are: `$PDFS_LOCALEDIR`, then the directory the build
|
||||
/// named, then `share/locale` beside the `bin` directory the program runs
|
||||
/// from when that holds a catalog of ours, then [`DEFAULT_LOCALEDIR`].
|
||||
///
|
||||
/// The third is for an install outside `/usr`, such as the release tarball's
|
||||
/// `install.sh` into `~/.local`: its programs find their translations without
|
||||
/// a wrapper setting the variable.
|
||||
fn locale_dir(env: Option<String>, build: Option<&str>, exe: Option<PathBuf>) -> PathBuf {
|
||||
if let Some(dir) = env.filter(|dir| !dir.is_empty()) {
|
||||
return PathBuf::from(dir);
|
||||
}
|
||||
if let Some(dir) = build {
|
||||
return PathBuf::from(dir);
|
||||
}
|
||||
let beside = exe
|
||||
.as_deref()
|
||||
.and_then(Path::parent)
|
||||
.and_then(Path::parent)
|
||||
.map(|prefix| prefix.join("share/locale"))
|
||||
.filter(|dir| {
|
||||
LANGUAGES
|
||||
.iter()
|
||||
.any(|(code, _)| dir.join(code).join("LC_MESSAGES/pdfs.mo").is_file())
|
||||
});
|
||||
beside.unwrap_or_else(|| PathBuf::from(DEFAULT_LOCALEDIR))
|
||||
}
|
||||
|
||||
/// The iso-codes text domain that translates ISO 3166-1 country names.
|
||||
const ISO_3166_DOMAIN: &str = "iso_3166-1";
|
||||
|
||||
@@ -234,6 +259,32 @@ fn fill(template: &str, args: &[(&str, &str)]) -> String {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn the_catalogs_are_found_beside_an_install_outside_usr() {
|
||||
let prefix = std::env::temp_dir().join(format!("pdfs-locale-{}", std::process::id()));
|
||||
let mo = prefix.join("share/locale/de/LC_MESSAGES/pdfs.mo");
|
||||
std::fs::create_dir_all(mo.parent().unwrap()).unwrap();
|
||||
std::fs::write(&mo, b"").unwrap();
|
||||
let exe = Some(prefix.join("bin/pdfs-app"));
|
||||
|
||||
assert_eq!(
|
||||
locale_dir(None, None, exe.clone()),
|
||||
prefix.join("share/locale")
|
||||
);
|
||||
// The variable and the build's own choice still win.
|
||||
assert_eq!(
|
||||
locale_dir(Some("/x".into()), Some("/y"), exe.clone()),
|
||||
PathBuf::from("/x")
|
||||
);
|
||||
assert_eq!(locale_dir(None, Some("/y"), exe), PathBuf::from("/y"));
|
||||
// A prefix without our catalogs falls back to the system's.
|
||||
assert_eq!(
|
||||
locale_dir(None, None, Some(PathBuf::from("/nonexistent/bin/pdfs-app"))),
|
||||
PathBuf::from(DEFAULT_LOCALEDIR)
|
||||
);
|
||||
let _ = std::fs::remove_dir_all(&prefix);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fill_replaces_named_placeholders_in_any_order() {
|
||||
assert_eq!(
|
||||
|
||||
@@ -398,12 +398,10 @@ fn open_manager(args: &[&str]) {
|
||||
/// Remember that the user hid the icon, so the next login's autostart and the
|
||||
/// app both leave it away, then exit.
|
||||
fn hide_tray() {
|
||||
if let Ok(dirs) = AppDirs::new() {
|
||||
let mut config = dirs.load_config();
|
||||
config.tray_hidden = true;
|
||||
if let Err(e) = dirs.save_config(&config) {
|
||||
tracing::warn!("hide tray icon: {e}");
|
||||
}
|
||||
if let Ok(dirs) = AppDirs::new()
|
||||
&& let Err(e) = dirs.update_config(|config| config.tray_hidden = true)
|
||||
{
|
||||
tracing::warn!("hide tray icon: {e}");
|
||||
}
|
||||
std::process::exit(0);
|
||||
}
|
||||
@@ -421,6 +419,10 @@ impl Tray for DriveTray {
|
||||
self.state.phase.icon().into()
|
||||
}
|
||||
|
||||
fn attention_icon_name(&self) -> String {
|
||||
self.icon_name()
|
||||
}
|
||||
|
||||
fn status(&self) -> Status {
|
||||
match self.state.phase {
|
||||
Phase::Attention | Phase::SessionExpired => Status::NeedsAttention,
|
||||
@@ -674,6 +676,22 @@ mod tests {
|
||||
assert_eq!(phase_of(false, 0, true, false), Phase::Synced);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn attention_states_supply_the_icon_the_tray_requests() {
|
||||
let mut tray = DriveTray {
|
||||
state: status_state(&status(""), &[], &[], Path::new("/m")),
|
||||
socket: PathBuf::new(),
|
||||
};
|
||||
for (phase, icon) in [
|
||||
(Phase::Attention, "dialog-warning-symbolic"),
|
||||
(Phase::SessionExpired, "dialog-password-symbolic"),
|
||||
] {
|
||||
tray.state.phase = phase;
|
||||
assert_eq!(tray.status(), Status::NeedsAttention);
|
||||
assert_eq!(tray.attention_icon_name(), icon);
|
||||
}
|
||||
}
|
||||
|
||||
fn status(extra: &str) -> Response {
|
||||
status_from(env!("CARGO_PKG_VERSION"), extra)
|
||||
}
|
||||
|
||||
@@ -24,7 +24,9 @@ const STOCK: &[&str] = &[
|
||||
// GTK's built-in icons
|
||||
"info-outline-symbolic",
|
||||
// Adwaita
|
||||
"application-x-executable-symbolic",
|
||||
"audio-x-generic-symbolic",
|
||||
"changes-prevent-symbolic",
|
||||
"checkbox-checked-symbolic",
|
||||
"checkbox-symbolic",
|
||||
"computer-symbolic",
|
||||
|
||||
@@ -109,6 +109,7 @@ a live account since.
|
||||
|
||||
| Entry | Title |
|
||||
|---|---|
|
||||
| [B291](#b291--on-fedora-45s-oo7-every-saved-sign-in-is-lost-at-the-next-reboot) | On Fedora 45's oo7, every saved sign-in is lost at the next reboot |
|
||||
| [B289](#b289--the-takeout-import-mixes-in-other-services-and-drops-location-and-live-photos) | The Takeout import mixes in other services and drops location and live photos |
|
||||
| [B288](#b288--an-interrupted-takeout-import-reads-as-finished-and-one-error-ends-it) | An interrupted Takeout import reads as finished, and one error ends it |
|
||||
| [B287](#b287--a-photo-draft-left-by-an-interrupted-upload-blocks-that-name) | A photo draft left by an interrupted upload blocks that name |
|
||||
@@ -305,6 +306,8 @@ a live account since.
|
||||
|
||||
| Entry | Title |
|
||||
|---|---|
|
||||
| [B292](#b292--two-programs-changing-settings-at-once-lose-one-of-the-changes) | Two programs changing settings at once lose one of the changes |
|
||||
| [B290](#b290--reopening-the-database-right-after-closing-it-can-be-refused-as-another-daemon) | Reopening the database right after closing it can be refused as another daemon |
|
||||
| [B276](#b276--a-stop-can-end-with-a-panic-in-a-thread-the-stop-never-waited-for) | A stop can end with a panic in a thread the stop never waited for |
|
||||
| [B258](#b258--journalctl--p-warning-shows-nothing-whatever-the-daemon-logged) | `journalctl -p warning` shows nothing, whatever the daemon logged |
|
||||
| [B256](#b256--pdfs-copy-right-after-a-save-copies-the-old-version) | `pdfs copy` right after a save copies the old version |
|
||||
@@ -392,6 +395,99 @@ a live account since.
|
||||
|
||||
Newest first.
|
||||
|
||||
### B292 — Two programs changing settings at once lose one of the changes
|
||||
|
||||
**Status:** Fixed
|
||||
|
||||
**Found:** 2026-11-15, reading every writer of `config.json` while adding settings to Preferences.
|
||||
|
||||
**Where:** `crates/pdfs-core/src/config.rs`, `AppDirs::save_config` and its callers in the app,
|
||||
the tray and the daemon
|
||||
|
||||
**Repro:** Change the cache size in Preferences (the daemon writes `cache_budget`) while the app
|
||||
saves the window size or the tray hides itself. Both read the file before either wrote it, and
|
||||
the one that wrote last puts the other setting back. Not seen in the field; the window is a few
|
||||
milliseconds, but more settings in the app make it more likely.
|
||||
|
||||
**Cause:** Every writer loaded the file, changed one field and wrote the whole file back, with
|
||||
nothing ordering them. The atomic rename kept the file whole, not the changes.
|
||||
|
||||
**Fix:** `AppDirs::update_config` reads, changes and writes under an `flock` on
|
||||
`config.json.lock`, and every writer goes through it. It refuses an unreadable file before
|
||||
applying the change (B223). A lock held longer than 5 seconds is reported as an error instead of
|
||||
waited on.
|
||||
|
||||
**Verified:** `cargo test -p pdfs-core config::tests` on 2026-11-15,
|
||||
`concurrent_changes_to_different_settings_are_all_kept` and
|
||||
`a_change_is_never_applied_over_an_unreadable_config`.
|
||||
|
||||
---
|
||||
|
||||
### B291 — On Fedora 45's oo7, every saved sign-in is lost at the next reboot
|
||||
|
||||
**Status:** Fixed, not verified live
|
||||
**Found:** 2026-11-15, from the reporter's package list in
|
||||
[issue #78](https://github.com/narrrl/proton-drive-linux/issues/78): `oo7-daemon-0.7.0~beta^1.e91b98a`,
|
||||
the build Fedora 45 and 46 ship as stable, from before oo7's
|
||||
[7fb11dd](https://github.com/linux-credentials/oo7/commit/7fb11dd111c4be8fec01996e3caa31c44fa962b3)
|
||||
("server: Write item changes to the keyring file"). See
|
||||
[the investigation](ISSUE-78.md#setsecret-is-kept-only-in-memory-in-fedoras-oo7).
|
||||
**Where:** `crates/pdfs-core/src/auth.rs`, `write_stored`; `proton-auth-rs` (`secret_service.rs`, moved from `crates/pdfs-core/src/secretservice.rs`)
|
||||
|
||||
**Repro:** With oo7-daemon at e91b98a, save the session blob, save it again with a new refresh
|
||||
token, and restart oo7-daemon. The read after the restart returns the first blob. The keyring
|
||||
store writes an existing item with `SetSecret`, and that oo7 build applies `SetSecret` only to the
|
||||
item in memory; the keyring file keeps what `CreateItem` wrote. Within a boot every read returns
|
||||
the new tokens, so nothing looks wrong. After a reboot the daemon resumes with the refresh token
|
||||
of the last `pdfs login`, which Proton spent long ago: `InvalidRefreshToken`, and the user has to
|
||||
sign in again. Typing the password at login, or the fixes for B284 and B285, change nothing.
|
||||
|
||||
**Cause:** A bug in that oo7 build, fixed in oo7 0.7.0 but not packaged by Fedora. Every token
|
||||
refresh pdfs saved went through the one call it does not persist.
|
||||
|
||||
**Fix:** An existing entry is saved by `CreateItem` with `replace`, which that build writes to the
|
||||
file: a new item in the old one's collection, with its label and all its attributes, so the
|
||||
provider replaces the old one. A duplicate that a provider leaves behind is removed; if it cannot
|
||||
be, the new item is taken out again and the save falls back to the usual `SetSecret`. The first
|
||||
save, a locked item, two matching items, or any failure before the new item exists also fall back
|
||||
to it. The connection used for this never shows a prompt. The daemon log now has a short
|
||||
fingerprint of the refresh token at each start and each save, so a log across a reboot shows
|
||||
whether the keyring returned the last token saved.
|
||||
|
||||
**Verified:** 2026-11-15, `real_secret_service_keeps_the_last_save_across_a_provider_restart`
|
||||
(ignored; needs a throwaway Secret Service) against oo7-daemon built at e91b98a: with the
|
||||
in-place write it reads `r1` after the restart, with this change `r3` and one item. The same test
|
||||
and `real_secret_service_survives_a_provider_restart` pass against gnome-keyring. Not yet run on
|
||||
a Fedora 45 desktop with a real account.
|
||||
|
||||
---
|
||||
|
||||
### B290 — Reopening the database right after closing it can be refused as another daemon
|
||||
|
||||
**Status:** Fixed, 2026-11-15
|
||||
**Found:** 2026-11-15, CI on `chore/release-3.8.0` (fd6b2d3):
|
||||
`db::tests::what_a_create_sent_outlives_a_newer_blob_its_trash_and_a_restart` failed once with
|
||||
"another Proton Drive daemon is already using /tmp/pdfs-create-sent-….db". It passes on its own.
|
||||
**Where:** `crates/pdfs-core/src/db/mod.rs`, `acquire_single_writer_lock`
|
||||
|
||||
**Repro:** In one process, drop a `Db` and open the same file again while another thread spawns a
|
||||
child process. Rare; seen once in about 500 tests that run in parallel, several of which spawn
|
||||
processes.
|
||||
|
||||
**Cause:** The single-writer lock is a `flock` on `<db>.lock`, and a `flock` belongs to the open
|
||||
file, not to one descriptor. A child holds a copy of every descriptor from its fork until its exec
|
||||
closes the `O_CLOEXEC` ones. A lock dropped by the parent in that moment stays held by the child,
|
||||
and an immediate reopen gets `EWOULDBLOCK`, which reads as a second daemon.
|
||||
|
||||
**Fix:** A refused lock is retried every 20 ms for up to 500 ms before it counts as another
|
||||
daemon. That covers any fork-to-exec window. A real second daemon is still refused, half a
|
||||
second later.
|
||||
|
||||
**Verified:** `cargo test -p pdfs-core` on 2026-11-15, including
|
||||
`a_second_writer_is_refused_while_the_first_holds_the_database`.
|
||||
|
||||
---
|
||||
|
||||
### B289 — The Takeout import mixes in other services and drops location and live photos
|
||||
|
||||
**Status:** Fixed, not verified live
|
||||
@@ -892,11 +988,16 @@ timing.
|
||||
**Where:** not located; the drain's conflict check in `crates/pdfs-fuse/src/drain.rs` is the
|
||||
first suspect
|
||||
|
||||
**Repro:** Only the CI run above. The last steps created `x/z/y/a.txt` (37 bytes), wrote 42
|
||||
**Repro:** The first CI failure created `x/z/y/a.txt` (37 bytes), wrote 42
|
||||
bytes into it at offset 20, and brought every link up. Drive then held the file at its first
|
||||
37 bytes, and the full content was in `x/z/y/a (sync-conflict …).txt`. No other client wrote
|
||||
to it.
|
||||
|
||||
On 2026-11-19, seed 1 of `one-client-echoes` showed the same symptom with delayed,
|
||||
duplicated, and reordered events. A two-byte overwrite of `x/d` appeared only in a
|
||||
conflict copy. Local replays passed. The simulation now retains its operation trace
|
||||
and daemon logs on failure. [CI run](https://github.com/narrrl/proton-drive-linux/actions/runs/44427290348)
|
||||
|
||||
**Cause.** Not known. Nothing was lost, since the conflict copy holds the bytes, but the file
|
||||
conflicted with its own create. B183 and B184 found the same symptom after a lost create
|
||||
reply.
|
||||
|
||||
@@ -11,6 +11,65 @@ scratch (user data in `staging/` and `recovery/` is never touched by this).
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Changed
|
||||
|
||||
- The shared Gallery engine now comes from the `proton-gallery-rs` and
|
||||
`proton-gallery-app-rs` crates on crates.io instead of a pinned Git revision of
|
||||
Proton Gallery. Builds, vendoring and the Nix package no longer fetch from Git.
|
||||
- RAW+JPEG grouping, Google Takeout reading, EXIF capture times, look-alike
|
||||
detection and the offline town lookup now come from `proton-gallery-rs`,
|
||||
shared with Proton Gallery. No behaviour change.
|
||||
- The keyring code (one Secret Service connection that reconnects after the provider
|
||||
restarts, B285, and replacing the session item instead of editing it, B291) now comes
|
||||
from `proton-auth-rs`, shared with Proton Gallery and Proton Stream. No behaviour change.
|
||||
- Config, machine-id and mount-failure files are written through `proton-base-rs`'s
|
||||
atomic writer (temporary file, sync, rename, directory sync). The mount-failure file
|
||||
is now synced before the rename too, so a crash cannot leave it empty.
|
||||
|
||||
## [3.9.0] — 2026-11-19
|
||||
|
||||
Schema: **46**. Photos adds a local database migration for incremental metadata sync.
|
||||
|
||||
### Added
|
||||
|
||||
- Open **Drive galleries** in Photos → Albums to browse saved My files folders and their
|
||||
subfolders, choose album covers, and manage public links. Saved galleries and
|
||||
covers sync with Proton Gallery on desktop and Android.
|
||||
- Unlock hidden albums from the Albums view with your Linux sign-in.
|
||||
|
||||
### Changed
|
||||
|
||||
- Photos uses Proton Gallery's justified row planner. The Photos viewer starts
|
||||
and seeks through supported videos without caching the whole original.
|
||||
- Gallery-hidden albums and their contents are filtered from Photos and Drive
|
||||
Galleries until unlocked.
|
||||
- Photo grids defer work for off-screen tiles and keep the viewed photo anchored
|
||||
during zoom.
|
||||
|
||||
### Fixed
|
||||
|
||||
- Unlocking Hidden albums keeps the private view open while its albums load.
|
||||
- Hovering over an album highlights its card without shading the surrounding grid cell.
|
||||
|
||||
## [3.8.1] — 2026-11-19
|
||||
|
||||
Schema: **45**. No database migration in this release.
|
||||
|
||||
### Changed
|
||||
|
||||
- Refreshed the application icon and project artwork, and updated the documentation screenshots.
|
||||
|
||||
### Fixed
|
||||
|
||||
- The cache skips pinned files when looking for space to reclaim and reapplies the configured
|
||||
limit when the service starts. Pinned files and recovery data are preserved.
|
||||
- Trashing a folder waits for queued moves out of it, including moves from nested subfolders.
|
||||
If a move is blocked by an item or folder already in Trash, Sync and `pdfs sync issues`
|
||||
identify what to restore before retrying.
|
||||
- The system tray displays a warning icon when sync needs attention or the session has expired.
|
||||
- Updated the Proton SDK to 0.12.1 so a fast local clock no longer causes Proton to reject
|
||||
uploads of new files and photos.
|
||||
|
||||
## [3.8.0] — 2026-11-14
|
||||
|
||||
Schema: **45**. Synced folders now tell device backups apart from folders attached to My files.
|
||||
@@ -18,6 +77,39 @@ Existing folders stay device backups. Older builds cannot open the upgraded data
|
||||
|
||||
### Added
|
||||
|
||||
- **Excluded files, opening files and the search launcher in Preferences** (#99). Settings that
|
||||
could only be changed in `config.json` now have a place in the app:
|
||||
- **Sync → Excluded Files**: the patterns every synced folder leaves out. Add your own, such as
|
||||
`*.db` or `build/`, and turn each built-in pattern on or off. A change applies at once.
|
||||
- **Sync → Conflict Copies**: whether identical conflict copies are only reported, moved to the
|
||||
trash, or not looked for.
|
||||
- **Apps → Open Files With**: which program opens which kind of file, in order, optionally in a
|
||||
terminal, for example `nvim` for text files. A change applies to the next file opened.
|
||||
- **Apps → Search Launcher**: whether `pdfs-prompt` opens its own window, your dmenu-style
|
||||
launcher (rofi, wofi, fuzzel, bemenu) or fzf in a terminal.
|
||||
|
||||
The Sync page's Folders view lists **Excluded Files** under the folders: how many patterns
|
||||
apply to all of them and to each one, and **Add Pattern** to add one for all synced folders or
|
||||
for a single folder. A folder's own rules (its `.pdfsignore`) open in an editor, also from the
|
||||
folder's menu. It checks every line as you type, tells you whether a path is synced and which
|
||||
pattern decides, and asks before replacing rules that changed on another computer meanwhile.
|
||||
`pdfs sync ignore list|add|remove|reset|check` does the same from a terminal, and `--folder`
|
||||
picks a single folder.
|
||||
`pdfs-app --page preferences-sync` (or `-apps`, `-storage`, plain `preferences`) opens
|
||||
Preferences at that page.
|
||||
- **More clutter left out of synced folders by default**: `desktop.ini`, `.directory`, trash
|
||||
folders, `.fuse_hidden*` and `.nfs*` leftovers, partial downloads (`*.part`, `*.crdownload`),
|
||||
Kate swap files and office lock files. This only changes folders where you never set your own
|
||||
list. Leaving a file out never deletes its copy on Proton Drive.
|
||||
- **An install without a package, for immutable distributions** (#99). The release `.tar.gz` now
|
||||
carries everything around the programs and an `install.sh` that installs them into your home
|
||||
folder, no root needed: `~/.local` for the programs, menu entry, icon, translations and shell
|
||||
completion, `~/.config` for the service and the tray's login entry. It checks the libraries
|
||||
first and names the packages to install, refuses to install next to a package of the client,
|
||||
updates in place (restarting a running service) and removes itself with `--uninstall`, leaving
|
||||
settings and data alone. The app finds its translations and the tray beside its own program, so
|
||||
nothing has to be on the `PATH`. [Installation](INSTALL.md) also shows how to layer the COPR
|
||||
package on Fedora Atomic (Silverblue, Kinoite, Bazzite, Bluefin).
|
||||
- **Sync a local folder with a folder you already have in My files** (#67, #77).
|
||||
`pdfs sync attach ~/Work --to Work` keeps `~/Work` an ordinary local folder and syncs it both
|
||||
ways with My files/Work. The first sync uploads files that are only on this computer, downloads
|
||||
@@ -146,6 +238,9 @@ Existing folders stay device backups. Older builds cannot open the upgraded data
|
||||
|
||||
### Fixed
|
||||
|
||||
- **Two programs changing settings at once no longer lose one of the changes** (B292). The app,
|
||||
the tray and the service now change `config.json` under a lock, so for example a new cache
|
||||
size saved by the service and the window size saved by the app both stay.
|
||||
- **Resuming a Google Photos import no longer fails at once** (#94, B286, B287). A photo upload
|
||||
that was cut short left a draft behind, and every later run stopped with
|
||||
`check for existing photos: serialization error: invalid type: null`. Such drafts are now
|
||||
@@ -162,13 +257,13 @@ Existing folders stay device backups. Older builds cannot open the upgraded data
|
||||
screen there, and with nothing to scroll no more were loaded. More now load whenever the photos
|
||||
don't fill the window, also after a zoom or a resize.
|
||||
|
||||
- **Signed out after a cold boot on Fedora 45** (issue #78, B284, B285). Fedora 45 replaced the
|
||||
GNOME keyring with oo7, and two things there could keep a refreshed sign-in from being saved:
|
||||
oo7 reports the entries of a locked keyring as missing, which the client took for a sign-out,
|
||||
and a restarted oo7 no longer knew the client's connection, which then failed every save until
|
||||
the service restarted. The refreshed sign-in lived only in memory, and the next boot found the
|
||||
spent one. The client now keeps such a sign-in and saves it once the keyring can be read, and
|
||||
reconnects to a keyring service that restarted.
|
||||
- **Signed out after every reboot on Fedora 45** (issue #78, B284, B285, B291). Fedora 45 replaced
|
||||
the GNOME keyring with oo7, and the oo7 build it ships keeps a changed keyring entry only in
|
||||
memory: every refreshed sign-in the client saved was gone after a reboot, and the next start
|
||||
found one Proton had already retired. The client now saves the sign-in as a new entry that
|
||||
replaces the old one, which that oo7 does write to disk. It also no longer drops a refreshed
|
||||
sign-in when oo7 reports the entries of a locked keyring as missing, and it reconnects to a
|
||||
keyring service that restarted.
|
||||
|
||||
- **Thumbnails appear in the folder you are looking at as soon as they are made.** During
|
||||
**Build thumbnails**, the folder on screen kept its file icons until you left it and opened it
|
||||
@@ -2317,6 +2412,8 @@ First stable release: FUSE files-on-demand mount, sync daemon under `proton-driv
|
||||
- The outstanding FUSE defects tracked in `docs/BUGS.md`, plus a truncate defect, validated
|
||||
by a new POSIX compliance suite for the filesystem.
|
||||
|
||||
[3.9.0]: https://github.com/narrrl/proton-drive-linux/releases/tag/v3.9.0
|
||||
[3.8.1]: https://github.com/narrrl/proton-drive-linux/releases/tag/v3.8.1
|
||||
[3.5.0]: https://github.com/narrrl/proton-drive-linux/releases/tag/v3.5.0
|
||||
[3.4.1]: https://github.com/narrrl/proton-drive-linux/releases/tag/v3.4.1
|
||||
[3.4.0]: https://github.com/narrrl/proton-drive-linux/releases/tag/v3.4.0
|
||||
|
||||
@@ -119,6 +119,10 @@ commands are for scripts and for cases where the mount is not available.
|
||||
| `pdfs sync reset ID` | Forget what a synced folder synced before and compare it with Proton Drive again. A file on one side only is copied to the other, and a file that differs keeps both versions. Nothing is deleted. |
|
||||
| `pdfs sync pause [--for 1h] [--folder ID]` | Pause uploads and synced folders. Reading files keeps working. `--for` ends the pause by itself (`30m`, `1h`, `2d`). |
|
||||
| `pdfs sync resume [--folder ID]` | Resume after a pause. |
|
||||
| `pdfs sync ignore list [--folder PATH]` | Print the patterns every synced folder leaves out; built-in ones are marked. With `--folder`, the own patterns of the synced folder holding `PATH`. |
|
||||
| `pdfs sync ignore add PATTERN [--folder PATH]` / `remove PATTERN [--folder PATH]` | Leave out, or stop leaving out, files matching a gitignore-style pattern such as `*.db` or `build/`, in every synced folder or, with `--folder`, in that folder's `.pdfsignore` only. A pattern starting with `-` goes after `--`. |
|
||||
| `pdfs sync ignore reset` | Use the built-in patterns again. |
|
||||
| `pdfs sync ignore check PATH` | Say whether a file in a synced folder is synced, and which pattern decides. |
|
||||
| `pdfs sync limit [--up RATE] [--down RATE]` | Cap bandwidth, for example `500K` or `2M` per second. `0` removes a cap. Without options, prints the current caps. |
|
||||
| `pdfs sync queue` | List changes that have not reached Proton Drive yet. |
|
||||
| `pdfs sync issues` | List queued changes Proton Drive refused or that keep failing, and what to do. |
|
||||
|
||||
@@ -44,9 +44,13 @@ the [security model](SECURITY_MODEL.md#what-is-kept-on-this-computer).
|
||||
## `config.json`
|
||||
|
||||
The file is created with defaults on first start. Every key is optional; a missing key takes its
|
||||
default. Edit it while the app is closed, then restart the service
|
||||
default. Most keys can be changed in the app, under **Preferences** (the "In app" column below).
|
||||
To edit the file by hand, close the app first, then restart the service
|
||||
(`systemctl --user restart proton-drive.service`) for service settings to apply.
|
||||
|
||||
The app, the tray and the service each change the file under a lock (`config.json.lock` next to
|
||||
it), so two of them changing different settings at once both keep their change.
|
||||
|
||||
An unreadable file is never overwritten: the programs log an error and run with defaults until you
|
||||
fix it.
|
||||
|
||||
@@ -80,9 +84,9 @@ fix it.
|
||||
| `cache_budget` | bytes | 5 GiB | Storage → Cache | Soft limit for cached content. `0` means unlimited. Available-offline files do not count against it |
|
||||
| `upload_limit` | bytes/s | none | General → Network | Shared cap for all uploads. `0` or `null` means none |
|
||||
| `download_limit` | bytes/s | none | General → Network | Shared cap for all downloads, reads from the mount included |
|
||||
| `ignore_patterns` | list | see below | — | Global ignore rules for synced folders |
|
||||
| `ignore_patterns` | list | see below | Sync → Excluded Files | Global ignore rules for synced folders |
|
||||
| `device_uid` | string | none | Computers → Continue This Backup Here… or Sync With This Computer… | The computer this machine syncs into. Unset means "match by hostname" |
|
||||
| `conflict_sweep` | `off` / `report` / `enforce` | `report` | — | See [`conflict_sweep`](#conflict_sweep) |
|
||||
| `conflict_sweep` | `off` / `report` / `enforce` | `report` | Sync → Conflict Copies | See [`conflict_sweep`](#conflict_sweep) |
|
||||
| `local_first` | bool | `true` | — | See [`local_first`](#local_first) |
|
||||
| `language` | gettext code | system | General → Appearance | Language of the app, tray and prompt, such as `de` or `pt_BR` |
|
||||
| `proton_theme` | bool | follow system | General → Appearance | Proton's colours instead of the system theme |
|
||||
@@ -93,8 +97,8 @@ fix it.
|
||||
| `update_latest` | version | none | — | The latest release the update check found |
|
||||
| `files_view` | object | grid, by name | My files view menu | `list`, `sort` (`name`, `size`, `modified`), `descending`, `folders_first` |
|
||||
| `window` | object | 980 × 680 | Resizing the app window | `width`, `height` (the unmaximized size), `maximized` |
|
||||
| `open_with` | object | `xdg-open` | — | See [`open_with`](#open_with) |
|
||||
| `prompt` | object | built-in window | — | See [`prompt`](#prompt) |
|
||||
| `open_with` | object | `xdg-open` | Apps → Open Files With | See [`open_with`](#open_with) |
|
||||
| `prompt` | object | built-in window | Apps → Search Launcher | See [`prompt`](#prompt) |
|
||||
|
||||
`app_version` and `user_agent` identify the client to Proton. When the keys are absent, the
|
||||
client sends its own release (`external-drive-linux@<version>-stable`, `proton-drive-linux/<version>`).
|
||||
@@ -109,10 +113,14 @@ Gitignore-style rules applied to every synced folder, in addition to each folder
|
||||
|
||||
```json
|
||||
[".git/", ".hg/", ".svn/", "node_modules/", "target/", ".venv/", "__pycache__/",
|
||||
"*~", "*.swp", "*.tmp", ".DS_Store", "Thumbs.db"]
|
||||
"*~", "*.swp", "*.tmp", ".DS_Store", "Thumbs.db",
|
||||
"desktop.ini", ".directory", ".Trash-*/", ".Trashes/", ".Spotlight-V100/",
|
||||
".fuse_hidden*", ".nfs*", "*.part", "*.crdownload", "*.kate-swp", ".~lock.*#", "~$*"]
|
||||
```
|
||||
|
||||
Set it to `[]` to turn the defaults off. See
|
||||
Preferences → Sync → Excluded Files edits this list, **Add Pattern** on the Sync page's Folders
|
||||
view adds to it, and `pdfs sync ignore` does the same from a terminal. A list equal to the defaults is saved as absent, so it follows the defaults of later
|
||||
releases. Set it to `[]` to turn the defaults off. See
|
||||
[Synced folders](SYNCED_FOLDERS.md#excluding-files-with-pdfsignore) for how excluding behaves.
|
||||
|
||||
### `conflict_sweep`
|
||||
|
||||
@@ -167,6 +167,7 @@ invented account, so they never show anyone's files:
|
||||
```bash
|
||||
scripts/screenshots.sh # all of them, into images/
|
||||
scripts/screenshots.sh --only photos,files # just these
|
||||
scripts/screenshots.sh --debug --skip-build # reuse already-built debug binaries
|
||||
scripts/screenshots.sh --website ../proton-drive-linux-website # and copy them to the website
|
||||
```
|
||||
|
||||
|
||||
@@ -21,7 +21,8 @@ again.
|
||||
| [Arch Linux](#arch-linux-aur) | `proton-drive-for-linux` in the AUR | With your AUR helper |
|
||||
| [Debian, Ubuntu 24.04 or newer](#debian-and-ubuntu-2404-or-newer) | `.deb` from the release page | Download each release |
|
||||
| [NixOS](#nixos-flake) | The flake in this repository | With `nix flake update` |
|
||||
| [Anything else](#other-distributions) | `.tar.gz` from the release page, or [build from source](#build-from-source) | By hand |
|
||||
| [Fedora Atomic](#fedora-atomic-silverblue-kinoite-bazzite-bluefin) (Silverblue, Kinoite, Bazzite, Bluefin) | The COPR repository, layered with `rpm-ostree` | With `rpm-ostree upgrade` |
|
||||
| [Anything else](#other-distributions), immutable ones included | `.tar.gz` from the release page, installed into your home folder by its `install.sh`, or [build from source](#build-from-source) | Run the new release's `install.sh` |
|
||||
|
||||
Release packages are for x86_64. You also need a Secret Service provider, such as GNOME
|
||||
Keyring, KWallet or KeePassXC, to keep your session. Most desktops have one already.
|
||||
@@ -139,12 +140,42 @@ the module) and a Secret Service such as GNOME Keyring or KWallet. To leave out
|
||||
it video thumbnails, override the package with `withFfmpeg = false`. The recipe is in
|
||||
[`packaging/nix/`](../packaging/nix/).
|
||||
|
||||
### Fedora Atomic (Silverblue, Kinoite, Bazzite, Bluefin)
|
||||
|
||||
The system is read-only, so layer the COPR package on top of it. It brings its libraries along:
|
||||
|
||||
```bash
|
||||
sudo curl -o /etc/yum.repos.d/proton-drive-linux.repo \
|
||||
"https://copr.fedorainfracloud.org/coprs/narl-rs/proton-drive-linux/repo/fedora-$(rpm -E %fedora)/narl-rs-proton-drive-linux-fedora-$(rpm -E %fedora).repo"
|
||||
rpm-ostree install proton-drive-linux
|
||||
systemctl reboot
|
||||
```
|
||||
|
||||
`rpm-ostree upgrade` brings new releases with the system's own updates.
|
||||
|
||||
### Other distributions
|
||||
|
||||
Unpack the `.tar.gz` from the [latest release](https://github.com/narrrl/proton-drive-linux/releases/latest)
|
||||
into a directory on your `PATH`, then install the service as shown in
|
||||
[Using a binary outside `/usr/bin`](#using-a-binary-outside-usrbin). The binaries need GTK 4.12,
|
||||
libadwaita 1.5, WebKitGTK 6.0 and FUSE 3; see [Requirements](#requirements).
|
||||
The `.tar.gz` from the [latest release](https://github.com/narrrl/proton-drive-linux/releases/latest)
|
||||
installs into your home folder, without root, so it also works where the system is read-only:
|
||||
|
||||
```bash
|
||||
tar -xzf proton-drive-linux-*-x86_64.tar.gz
|
||||
proton-drive-linux-*-x86_64/install.sh
|
||||
```
|
||||
|
||||
It puts the programs in `~/.local/bin`, the menu entry, icon, translations and shell completion in
|
||||
`~/.local/share`, the service in `~/.config/systemd/user` and the tray's login entry in
|
||||
`~/.config/autostart`, each pointing at `~/.local/bin`. Then open **Proton Drive for Linux** from
|
||||
your applications menu. `--prefix DIR` installs somewhere else.
|
||||
|
||||
The system has to provide glibc 2.39 or newer (the binaries are built on Ubuntu 24.04), GTK 4.12,
|
||||
libadwaita 1.5, WebKitGTK 6.0 and FUSE 3 with a setuid `fusermount3`; see
|
||||
[Requirements](#requirements). `install.sh` checks the libraries first and names the packages to
|
||||
install for each distribution. It refuses to install next to a package of this client, since the
|
||||
two would run different versions of the service.
|
||||
|
||||
To update, download the new release and run its `install.sh`; a running service restarts on the new
|
||||
version. Turn on **Preferences → General → Check for updates** to hear about new releases.
|
||||
|
||||
## Optional extras
|
||||
|
||||
@@ -195,7 +226,9 @@ browser, solve it, then press Enter.
|
||||
| COPR (Fedora) | `sudo dnf upgrade` |
|
||||
| AUR | `paru -Syu`, or your AUR helper's equivalent |
|
||||
| Nix flake | `nix flake update proton-drive-linux`, or change the pinned tag, then rebuild |
|
||||
| `.deb`, release `.rpm`, `.tar.gz` | Download the new release and install it over the old one |
|
||||
| Fedora Atomic | `rpm-ostree upgrade`, then reboot |
|
||||
| `.deb`, release `.rpm` | Download the new release and install it over the old one |
|
||||
| `.tar.gz` | Download the new release and run its `install.sh` |
|
||||
|
||||
The service switches to the new version the next time it starts. To switch at once:
|
||||
|
||||
@@ -245,6 +278,8 @@ open in an older release, so going back to an older version means clearing the l
|
||||
| `.deb` | `sudo apt remove proton-drive-linux` |
|
||||
| AUR | `sudo pacman -R proton-drive-for-linux` (or the `-bin` or `-git` package) |
|
||||
| NixOS | Remove the module and the flake input, then rebuild |
|
||||
| Fedora Atomic | `rpm-ostree uninstall proton-drive-linux`, remove `/etc/yum.repos.d/proton-drive-linux.repo`, then reboot |
|
||||
| `.tar.gz` | `~/.local/share/proton-drive-linux/install.sh --uninstall` |
|
||||
|
||||
Removing the package also stops the service of every logged-in user, in case step 1 was
|
||||
skipped.
|
||||
@@ -353,8 +388,10 @@ sudo dnf install packaging/out/x86_64/proton-drive-linux-*.rpm
|
||||
|
||||
### Using a binary outside `/usr/bin`
|
||||
|
||||
The service unit starts `/usr/bin/pdfs daemon`. If you installed the programs somewhere else, for
|
||||
example `~/.local/bin`, install the unit for your user and point it at your binary:
|
||||
The release tarball's `install.sh` does all of this for you (see
|
||||
[Other distributions](#other-distributions)). For programs you built yourself: the service unit
|
||||
starts `/usr/bin/pdfs daemon`. If you installed the programs somewhere else, for example
|
||||
`~/.local/bin`, install the unit for your user and point it at your binary:
|
||||
|
||||
```bash
|
||||
mkdir -p ~/.config/systemd/user
|
||||
@@ -382,3 +419,7 @@ Every package installs the same files:
|
||||
| `/usr/lib/systemd/user/proton-drive.service` | User service that keeps the drive mounted |
|
||||
| `/etc/xdg/autostart/io.narl.proton-drive-linux-tray.desktop` | Starts the tray at login |
|
||||
| `/usr/share/locale/*/LC_MESSAGES/pdfs.mo` | Translations |
|
||||
|
||||
The release tarball's `install.sh` puts the same files under `~/.local` instead of `/usr`, the
|
||||
service in `~/.config/systemd/user` and the tray's login entry in `~/.config/autostart`. It keeps a
|
||||
list of them in `~/.local/share/proton-drive-linux/installed-files` for `--uninstall`.
|
||||
@@ -58,6 +58,52 @@ can resolve the default alias to a locked collection. Both have fixes in
|
||||
after the reporter's November 7 retest. Neither can be assigned as this report's cause without
|
||||
matching runtime evidence.
|
||||
|
||||
## SetSecret is kept only in memory in Fedora's oo7
|
||||
|
||||
Follow-up on 2026-11-15. The reporter's `rpm -qa 'oo7*'` shows
|
||||
`oo7-daemon-0.7.0~beta^1.e91b98a-1.fc45`, not the 0.7.0 release assumed above. Bodhi lists that
|
||||
build as the stable oo7 for Fedora 45 and 46; neither has 0.7.0 or 0.7.1. Commit e91b98a
|
||||
(October 24) predates
|
||||
[7fb11dd](https://github.com/linux-credentials/oo7/commit/7fb11dd111c4be8fec01996e3caa31c44fa962b3)
|
||||
(October 28): "Setting the Label or Attributes of an item, or calling SetSecret, only changed the
|
||||
item in memory, so the old values came back once the daemon restarted." 0.7.0 carries it as
|
||||
37e3334.
|
||||
|
||||
pdfs writes an existing entry with `SetSecret`, so on that build every saved token rotation was
|
||||
lost at the next reboot. This explains the reporter's log: the keyring was unlocked one second
|
||||
before pdfs started (they type their password at login) and still held a spent refresh token.
|
||||
It does not need a locked keyring or a restarted provider.
|
||||
|
||||
pdfs now saves an existing entry with `CreateItem` and `replace` instead
|
||||
(`crates/pdfs-core/src/secretservice.rs`, B291), which e91b98a writes to the keyring file.
|
||||
Reproduced and verified with oo7-daemon built at e91b98a in a throwaway session bus:
|
||||
|
||||
```sh
|
||||
git clone https://github.com/linux-credentials/oo7.git /tmp/oo7 && git -C /tmp/oo7 checkout e91b98a
|
||||
cargo build --manifest-path /tmp/oo7/Cargo.toml -p oo7-daemon --bin oo7-daemon
|
||||
OO7=/tmp/oo7/target/debug/oo7-daemon
|
||||
T=$(mktemp -d /tmp/ss.XXXX); mkdir -p $T/data $T/run; chmod 700 $T/run
|
||||
XDG_DATA_HOME=$T/data XDG_RUNTIME_DIR=$T/run OO7=$OO7 PDFS_SECRET_SERVICE_RESTART_TEST=1 \
|
||||
PDFS_RESTART_PROVIDER='pkill -x oo7-daemon; sleep 1; (printf pw | setsid "$OO7" --login >/dev/null 2>&1 &); sleep 2' \
|
||||
dbus-run-session -- sh -c 'printf pw | setsid "$OO7" --login >/dev/null 2>&1 & sleep 2;
|
||||
cargo test -p pdfs-core real_secret_service_keeps -- --ignored'
|
||||
```
|
||||
|
||||
With the in-place write, the read after the restart returns the first of three saves (`r1`);
|
||||
with the replacing write it returns the last (`r3`), and one item is left.
|
||||
|
||||
The daemon also logs a short fingerprint of the refresh token when it resumes the stored session
|
||||
and each time it saves a rotation (`refresh=1a2b3c4d`). If a start is refused, compare the
|
||||
fingerprint it resumed with against the last one saved in the boot before:
|
||||
|
||||
```sh
|
||||
journalctl --user -b -1 -u proton-drive.service | grep -E 'refresh=' | tail -2
|
||||
journalctl --user -b 0 -u proton-drive.service | grep -E 'refresh=' | head -2
|
||||
```
|
||||
|
||||
The same fingerprint means the keyring kept the last save and Proton refused it; a different one
|
||||
means the keyring lost it.
|
||||
|
||||
## A restarted Secret Service
|
||||
|
||||
A second path to the same symptom, independent of locking (B285). The keyring store pdfs used
|
||||
|
||||
@@ -69,9 +69,10 @@ windowrulev2 = center, class:^(pdfs-prompt)$
|
||||
bind = SUPER, space, exec, pdfs-prompt --fzf
|
||||
```
|
||||
|
||||
To make `--dmenu` or `--fzf` the default without changing your shortcut, set `prompt.mode` in
|
||||
`config.json` (see [Configuration → `prompt`](CONFIGURATION.md#prompt)). `--gtk` always opens the
|
||||
built-in window.
|
||||
To make `--dmenu` or `--fzf` the default without changing your shortcut, pick it in
|
||||
**Preferences → Apps → Search Launcher**, or set `prompt.mode` in `config.json` (see
|
||||
[Configuration → `prompt`](CONFIGURATION.md#prompt)). `--gtk` always opens the built-in window.
|
||||
Which program opens a file you pick is set under **Preferences → Apps → Open Files With**.
|
||||
|
||||
## Tray
|
||||
|
||||
|
||||
@@ -1,5 +1,39 @@
|
||||
# Photos
|
||||
|
||||
## How Photos is organized
|
||||
|
||||
Timeline, Albums, and Places share the same Photos workspace. The Timeline opens
|
||||
with the media type, Filters, and, where available, **On this day**. Albums
|
||||
contains the two collections **Proton albums** and **Drive galleries**. Add a
|
||||
gallery by choosing a folder from **My files**. Opening it or any subfolder
|
||||
keeps you in Photos. Back or Escape returns to the parent and its scroll
|
||||
position.
|
||||
|
||||
**Hidden albums** opens with your Linux sign-in. The app uses the desktop
|
||||
polkit prompt, so it needs a running authentication agent and the installed
|
||||
polkit policy. Existing hidden albums remain hidden after upgrading. This view
|
||||
includes hidden Proton albums and hidden Drive folders, including folders
|
||||
inside public galleries. Leaving Hidden albums or switching away from the
|
||||
window locks it and closes its previews.
|
||||
|
||||
For a system package, the policy is installed with the app. For a source build
|
||||
or a per-user tarball install, have your system administrator install
|
||||
`packaging/io.narl.proton-drive-linux.policy` (or the corresponding file under the
|
||||
tarball's `share/polkit-1/actions/`) into the system polkit actions directory.
|
||||
On NixOS, enable `security.polkit` and install the package system-wide to
|
||||
register its policy.
|
||||
|
||||
GTK pages Timeline, Proton albums, and Places through the Drive daemon's Photos
|
||||
control requests backed by its SQLite database. Saved Drive galleries come from
|
||||
the shared Proton Gallery catalog, which the daemon hosts for the signed-in
|
||||
account. Photos applies that catalog's visibility rules to public queries.
|
||||
Hidden albums use separate, unlock-gated requests. Thumbnails in the hidden
|
||||
view are kept in memory and cleared on lock.
|
||||
|
||||
Ctrl+mousewheel changes timeline tile size. GTK updates only the changed row
|
||||
range and keeps the visible photo in place. As you scroll, each new page
|
||||
updates the last affected section and adds new sections below it.
|
||||
|
||||
The **Photos** page of the app shows your Proton Photos library. Photos are stored apart from
|
||||
My files, so they do not appear in `~/ProtonDrive`.
|
||||
|
||||
|
||||
@@ -100,10 +100,39 @@ apply together:
|
||||
!important.log
|
||||
```
|
||||
|
||||
2. The `ignore_patterns` list in `config.json`, for every synced folder (see
|
||||
[Configuration](CONFIGURATION.md#ignore_patterns)). When you have not set it, it skips
|
||||
`.git/`, `.hg/`, `.svn/`, `node_modules/`, `target/`, `.venv/`, `__pycache__/`, `*~`,
|
||||
`*.swp`, `*.tmp`, `.DS_Store` and `Thumbs.db`.
|
||||
2. The patterns for every synced folder: **Preferences → Sync → Excluded Files** in the app, or
|
||||
`ignore_patterns` in `config.json` (see [Configuration](CONFIGURATION.md#ignore_patterns)).
|
||||
Built in are version control (`.git/`, `.hg/`, `.svn/`), dependency and build folders
|
||||
(`node_modules/`, `target/`, `.venv/`, `__pycache__/`), and what editors, downloads and other
|
||||
systems leave behind (`*~`, `*.swp`, `*.tmp`, `*.part`, `*.crdownload`, `*.kate-swp`, office
|
||||
lock files, `.DS_Store`, `Thumbs.db`, `desktop.ini`, `.directory`, trash folders, `.nfs*` and
|
||||
`.fuse_hidden*`). Each built-in pattern can be turned off on its own.
|
||||
|
||||
In the app, open the **Sync** page, then **Folders**. Under the folder list, **Excluded Files**
|
||||
shows how many patterns apply to all synced folders and how many each folder has of its own:
|
||||
|
||||
- **Add Pattern** asks for a pattern and where it applies: all synced folders, or one of them.
|
||||
- **All Synced Folders** opens Preferences → Sync, with every pattern and the built-in ones.
|
||||
- A folder opens the editor for its own rules, which **Excluded Files…** in the folder's menu
|
||||
opens too. It checks every line as you type, and **Check a path** tells you whether a file is
|
||||
synced and which pattern decides. If the file changed meanwhile, for example on another
|
||||
computer, it asks before replacing that version.
|
||||
|
||||
From a terminal:
|
||||
|
||||
```bash
|
||||
pdfs sync ignore list # the patterns for every synced folder
|
||||
pdfs sync ignore add '*.db' # leave out files ending in .db
|
||||
pdfs sync ignore remove '*.db'
|
||||
pdfs sync ignore reset # back to the built-in patterns
|
||||
pdfs sync ignore add 'cache/' --folder ~/Projects # only in ~/Projects/.pdfsignore
|
||||
pdfs sync ignore list --folder ~/Projects
|
||||
pdfs sync ignore check ~/Projects/app/node_modules
|
||||
```
|
||||
|
||||
The rules apply to folders kept on this computer. Files you save into `~/ProtonDrive` itself or into
|
||||
an online-only folder are always uploaded, except download and editor scratch files, which wait for
|
||||
their final name.
|
||||
|
||||
Rules are read again on every sync pass. Excluding never deletes anything: a file that becomes
|
||||
excluded is no longer synced, and its copy on Proton Drive stays.
|
||||
|
||||
@@ -75,7 +75,8 @@ PDFS_SIM_SEED=7 RUST_LOG=pdfs_fuse=debug cargo test -p pdfs-fuse --lib \
|
||||
| `PDFS_SIM_MEASURE` | Run `a_thousand_files_drain_as_fast_on_wifi_as_on_lan`, which times 1,000 files in 100 folders on a LAN and a Wi-Fi profile and prints the times |
|
||||
|
||||
A failure is a seed that can be replayed, but the daemon uses real threads, so a race may need
|
||||
several replays. In CI, the `simulation` job uploads the stacks of a hung run as an artifact.
|
||||
several replays. In CI, the `simulation` job uploads the failed seed's steps and daemon logs,
|
||||
along with thread stacks when the watchdog catches a hang.
|
||||
|
||||
## Acceptance suite
|
||||
|
||||
|
||||
@@ -53,6 +53,8 @@ The app uses these words, and so do these pages:
|
||||
| Page | Settings |
|
||||
|---|---|
|
||||
| **General** | Start on login · Proton Drive folder location · upload and download limits · Proton theme, street map for Places, tray icon · language · check for updates |
|
||||
| **Sync** | Files and folders every synced folder leaves out · what happens to identical conflict copies |
|
||||
| **Apps** | Which program opens which kind of file · how the search launcher opens |
|
||||
| **Storage** | Cache size limit · clear the cache · files kept available offline |
|
||||
|
||||
The account menu shows the storage you use and holds **Sign Out…**. Settings that are not in the
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
# Violet / Copper vector branding
|
||||
|
||||
Drive, Stream, and Gallery share frontal violet–pink faces, shallow metallic copper backing, and narrow edge highlights. The icons are editable vector artwork with no embedded images or raster effects.
|
||||
|
||||
| App | Mark |
|
||||
| --- | --- |
|
||||
| Proton Drive for Linux | Open folder with lilac documents |
|
||||
| Proton Stream | Rounded play prism |
|
||||
| Proton Gallery | Stacked photo plates, mountains, and a copper sun |
|
||||
|
||||
## Master artwork
|
||||
|
||||
Edit `images/logo.svg`. It uses a 256-unit grid with transparent margins, a `mark` group, and reusable linear gradients. The copper backing extends six units up and right. SVG paths, rounded rectangles, circles, strokes, translation, and the photo clip are retained when exporting Android VectorDrawables. Unsupported SVG features cause generation to fail rather than silently change the artwork.
|
||||
|
||||
Earlier artwork is preserved in `images/branding-archive/`. The new assets replace the active branding without removing previous designs.
|
||||
|
||||
## Regeneration
|
||||
|
||||
```sh
|
||||
python scripts/render-branding.py
|
||||
python scripts/render-branding.py --check
|
||||
```
|
||||
|
||||
Requires Python 3, librsvg (`rsvg-convert`), and ImageMagick (`magick`). Stream's TV banner also requires fontconfig and DejaVu Sans. Keep the generator identical across the three repositories; every checkout renders independently and requires no sibling checkout. Edit the canonical master rather than generated platform assets.
|
||||
|
||||
## Platform treatment
|
||||
|
||||
- Desktop SVGs and PNGs retain transparent margins and the exact approved geometry. The same colored artwork works on light and dark surfaces.
|
||||
- Android adaptive icons use a pale lavender full-bleed background and a separate foreground containing the complete object. The 256-unit canvas maps to the central 64dp of the 108dp adaptive canvas; the painted geometry stays within the central safe circle. Android supplies the outer mask.
|
||||
- Themed launcher icons and Stream's status-bar notification icon use a white silhouette without colored bevel highlights.
|
||||
- iOS uses the same play prism over an opaque pale lavender square, exported at 1024px. The system supplies the corner mask.
|
||||
- The Android TV banner pairs the play prism with the full Proton Stream name.
|
||||
|
||||
Keep full product names in launcher metadata. Application UI typography and photo-content icons are independent of this branding.
|
||||
|
||||
## Outputs
|
||||
|
||||
`packaging/io.narl.proton-drive-linux.svg` is installed by the desktop packages and embedded in the GTK resource bundle for in-app branding.
|
||||
|
||||
The Drive cover (`images/cover.svg` and `images/cover.png`) also embeds the canonical icon. The generator updates its `app-logo` group while preserving the surrounding cover layout.
|
||||
|
After Width: | Height: | Size: 363 KiB |
@@ -0,0 +1,156 @@
|
||||
<svg width="1920" height="1080" viewBox="0 0 1920 1080" xmlns="http://www.w3.org/2000/svg">
|
||||
<defs>
|
||||
<linearGradient id="bg" x1="0" y1="0" x2="1920" y2="1080" gradientUnits="userSpaceOnUse">
|
||||
<stop offset="0" stop-color="#1A1240"/>
|
||||
<stop offset="1" stop-color="#0A0618"/>
|
||||
</linearGradient>
|
||||
<radialGradient id="glow1" cx="1390" cy="520" r="640" gradientUnits="userSpaceOnUse">
|
||||
<stop offset="0" stop-color="#6D4AFF" stop-opacity="0.55"/>
|
||||
<stop offset="0.5" stop-color="#6D4AFF" stop-opacity="0.15"/>
|
||||
<stop offset="1" stop-color="#6D4AFF" stop-opacity="0"/>
|
||||
</radialGradient>
|
||||
<radialGradient id="glow2" cx="160" cy="1080" r="700" gradientUnits="userSpaceOnUse">
|
||||
<stop offset="0" stop-color="#A855F7" stop-opacity="0.25"/>
|
||||
<stop offset="1" stop-color="#A855F7" stop-opacity="0"/>
|
||||
</radialGradient>
|
||||
<pattern id="dots" width="32" height="32" patternUnits="userSpaceOnUse">
|
||||
<circle cx="2" cy="2" r="1.6" fill="#FFFFFF"/>
|
||||
</pattern>
|
||||
<radialGradient id="dotfade" cx="1390" cy="520" r="900" gradientUnits="userSpaceOnUse">
|
||||
<stop offset="0" stop-color="#FFFFFF" stop-opacity="1"/>
|
||||
<stop offset="1" stop-color="#FFFFFF" stop-opacity="0"/>
|
||||
</radialGradient>
|
||||
<mask id="dotmask" maskUnits="userSpaceOnUse" x="0" y="0" width="1920" height="1080">
|
||||
<rect width="1920" height="1080" fill="url(#dotfade)"/>
|
||||
</mask>
|
||||
<linearGradient id="title2" x1="140" y1="0" x2="760" y2="0" gradientUnits="userSpaceOnUse">
|
||||
<stop offset="0" stop-color="#C9BBFF"/>
|
||||
<stop offset="1" stop-color="#8A6CFF"/>
|
||||
</linearGradient>
|
||||
|
||||
<!-- app logo -->
|
||||
<linearGradient id="pdl-face" x1="12" y1="12" x2="116" y2="112" gradientUnits="userSpaceOnUse">
|
||||
<stop offset="0" stop-color="#A48BFF"/>
|
||||
<stop offset="0.55" stop-color="#7552FF"/>
|
||||
<stop offset="1" stop-color="#5B36F2"/>
|
||||
</linearGradient>
|
||||
<linearGradient id="pdl-cloud" x1="0" y1="34" x2="0" y2="88" gradientUnits="userSpaceOnUse">
|
||||
<stop offset="0" stop-color="#FFFFFF"/>
|
||||
<stop offset="1" stop-color="#ECE6FF"/>
|
||||
</linearGradient>
|
||||
<mask id="pdl-cut" maskUnits="userSpaceOnUse" x="0" y="0" width="128" height="128">
|
||||
<g fill="#FFFFFF">
|
||||
<circle cx="66" cy="57" r="23"/>
|
||||
<circle cx="42" cy="68" r="16"/>
|
||||
<circle cx="88" cy="69" r="15"/>
|
||||
<rect x="26" y="68" width="77" height="20" rx="10"/>
|
||||
</g>
|
||||
<g stroke="#000000" stroke-width="7.5" stroke-linecap="round" stroke-linejoin="round" fill="none">
|
||||
<path d="M64 49v26"/>
|
||||
<path d="M54.5 65.5l9.5 9.5 9.5-9.5"/>
|
||||
</g>
|
||||
</mask>
|
||||
<filter id="logoshadow" x="-50%" y="-50%" width="200%" height="200%">
|
||||
<feGaussianBlur stdDeviation="6"/>
|
||||
</filter>
|
||||
<filter id="chipshadow" x="-50%" y="-50%" width="200%" height="200%">
|
||||
<feGaussianBlur stdDeviation="14"/>
|
||||
</filter>
|
||||
</defs>
|
||||
|
||||
<!-- background -->
|
||||
<rect width="1920" height="1080" fill="url(#bg)"/>
|
||||
<rect width="1920" height="1080" fill="url(#glow2)"/>
|
||||
<rect width="1920" height="1080" fill="url(#glow1)"/>
|
||||
<rect width="1920" height="1080" fill="url(#dots)" opacity="0.07" mask="url(#dotmask)"/>
|
||||
|
||||
<!-- orbit rings -->
|
||||
<g fill="none" stroke="#FFFFFF">
|
||||
<circle cx="1390" cy="520" r="300" stroke-opacity="0.10" stroke-width="2"/>
|
||||
<circle cx="1390" cy="520" r="420" stroke-opacity="0.06" stroke-width="2" stroke-dasharray="4 14" stroke-linecap="round"/>
|
||||
</g>
|
||||
|
||||
<!-- logo, 128 -> 384 -->
|
||||
<g transform="translate(1198 328) scale(3)">
|
||||
<rect x="16" y="24" width="96" height="92" rx="24" fill="#2A1080" opacity="0.8" filter="url(#logoshadow)"/>
|
||||
<rect x="12" y="16" width="104" height="100" rx="26" fill="#4424C0"/>
|
||||
<rect x="12" y="12" width="104" height="100" rx="26" fill="url(#pdl-face)"/>
|
||||
<rect x="12.5" y="12.5" width="103" height="99" rx="25.5" fill="none" stroke="#FFFFFF" stroke-opacity="0.2"/>
|
||||
<rect y="3" width="128" height="128" fill="#2E1596" fill-opacity="0.3" mask="url(#pdl-cut)"/>
|
||||
<rect width="128" height="128" fill="url(#pdl-cloud)" mask="url(#pdl-cut)"/>
|
||||
</g>
|
||||
|
||||
<!-- feature chips around the logo -->
|
||||
<g font-family="Adwaita Sans" font-size="26" font-weight="600" fill="#FFFFFF">
|
||||
<!-- folder, top left -->
|
||||
<g transform="translate(1000 200)">
|
||||
<rect x="0" y="10" width="236" height="76" rx="22" fill="#000000" opacity="0.35" filter="url(#chipshadow)"/>
|
||||
<rect x="0" y="0" width="236" height="76" rx="22" fill="#2A2058" fill-opacity="0.85" stroke="#FFFFFF" stroke-opacity="0.14" stroke-width="1.5"/>
|
||||
<g transform="translate(22 20)">
|
||||
<rect width="36" height="36" rx="10" fill="#6D4AFF"/>
|
||||
<path d="M8 13a2 2 0 0 1 2-2h5l2.5 2.5H26a2 2 0 0 1 2 2V25a2 2 0 0 1-2 2H10a2 2 0 0 1-2-2z" fill="#FFFFFF"/>
|
||||
</g>
|
||||
<text x="74" y="47">On demand</text>
|
||||
</g>
|
||||
<!-- sync, top right -->
|
||||
<g transform="translate(1590 290)">
|
||||
<rect x="0" y="10" width="164" height="76" rx="22" fill="#000000" opacity="0.35" filter="url(#chipshadow)"/>
|
||||
<rect x="0" y="0" width="164" height="76" rx="22" fill="#2A2058" fill-opacity="0.85" stroke="#FFFFFF" stroke-opacity="0.14" stroke-width="1.5"/>
|
||||
<g transform="translate(22 20)">
|
||||
<rect width="36" height="36" rx="10" fill="#1EA885"/>
|
||||
<g fill="none" stroke="#FFFFFF" stroke-width="2.6" stroke-linecap="round" stroke-linejoin="round">
|
||||
<path d="M26 15a8.5 8.5 0 0 0-15-2"/>
|
||||
<path d="M10 9v4.5h4.5"/>
|
||||
<path d="M10 21a8.5 8.5 0 0 0 15 2"/>
|
||||
<path d="M26 27v-4.5h-4.5"/>
|
||||
</g>
|
||||
</g>
|
||||
<text x="74" y="47">Sync</text>
|
||||
</g>
|
||||
<!-- photos, bottom right -->
|
||||
<g transform="translate(1560 690)">
|
||||
<rect x="0" y="10" width="206" height="76" rx="22" fill="#000000" opacity="0.35" filter="url(#chipshadow)"/>
|
||||
<rect x="0" y="0" width="206" height="76" rx="22" fill="#2A2058" fill-opacity="0.85" stroke="#FFFFFF" stroke-opacity="0.14" stroke-width="1.5"/>
|
||||
<g transform="translate(22 20)">
|
||||
<rect width="36" height="36" rx="10" fill="#E8618C"/>
|
||||
<rect x="8" y="9" width="20" height="18" rx="3" fill="none" stroke="#FFFFFF" stroke-width="2.4"/>
|
||||
<circle cx="14" cy="15" r="2" fill="#FFFFFF"/>
|
||||
<path d="M9.5 25l6-6 4 4 3-3 4 4" fill="none" stroke="#FFFFFF" stroke-width="2.4" stroke-linejoin="round"/>
|
||||
</g>
|
||||
<text x="74" y="47">Photos</text>
|
||||
</g>
|
||||
<!-- terminal, bottom left -->
|
||||
<g transform="translate(980 790)">
|
||||
<rect x="0" y="10" width="206" height="76" rx="22" fill="#000000" opacity="0.35" filter="url(#chipshadow)"/>
|
||||
<rect x="0" y="0" width="206" height="76" rx="22" fill="#2A2058" fill-opacity="0.85" stroke="#FFFFFF" stroke-opacity="0.14" stroke-width="1.5"/>
|
||||
<g transform="translate(22 20)">
|
||||
<rect width="36" height="36" rx="10" fill="#3B3F5C"/>
|
||||
<path d="M9 12l6 6-6 6" fill="none" stroke="#FFFFFF" stroke-width="2.6" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
<path d="M18 25h9" stroke="#FFFFFF" stroke-width="2.6" stroke-linecap="round"/>
|
||||
</g>
|
||||
<text x="74" y="48" font-family="JetBrainsMono NF" font-size="25" font-weight="700">pdfs</text>
|
||||
<text x="150" y="48" font-weight="500" fill="#B9B0D9">CLI</text>
|
||||
</g>
|
||||
</g>
|
||||
|
||||
<!-- text block -->
|
||||
<g font-family="Adwaita Sans">
|
||||
<g transform="translate(140 292)">
|
||||
<rect width="410" height="48" rx="24" fill="#6D4AFF" fill-opacity="0.18" stroke="#8A6CFF" stroke-opacity="0.6" stroke-width="1.5"/>
|
||||
<circle cx="28" cy="24" r="6" fill="#A48BFF"/>
|
||||
<text x="46" y="32" font-size="21" font-weight="700" letter-spacing="2.4" fill="#D6CCFF">UNOFFICIAL · OPEN SOURCE</text>
|
||||
</g>
|
||||
<text x="134" y="478" font-size="124" font-weight="800" letter-spacing="-3" fill="#FFFFFF">Proton Drive</text>
|
||||
<text x="134" y="610" font-size="124" font-weight="800" letter-spacing="-3" fill="url(#title2)">for Linux</text>
|
||||
<text x="140" y="702" font-size="38" font-weight="400" fill="#B9B0D9">Your Drive as a folder, and a native GTK4 app.</text>
|
||||
<text x="140" y="752" font-size="38" font-weight="400" fill="#B9B0D9">No Electron.</text>
|
||||
</g>
|
||||
|
||||
<!-- footer -->
|
||||
<g font-family="JetBrainsMono NF" font-size="24" fill="#8C83B0">
|
||||
<text x="140" y="968">github.com/narrrl/proton-drive-linux</text>
|
||||
</g>
|
||||
<g font-family="Adwaita Sans" font-size="22" fill="#6F6894">
|
||||
<text x="1780" y="968" text-anchor="end">Not affiliated with Proton AG</text>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 8.3 KiB |
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="128" height="128" viewBox="0 0 128 128"
|
||||
role="img" aria-label="Proton Drive for Linux" data-app="drive">
|
||||
<title>Proton Drive for Linux</title>
|
||||
<desc>A custom faceted D with an inset mount channel, in violet warming to copper.</desc>
|
||||
<!-- Canonical artwork. Regenerate platform assets with scripts/render-branding.py. -->
|
||||
<defs>
|
||||
<linearGradient id="face" x1="18" y1="12" x2="112" y2="116" gradientUnits="userSpaceOnUse">
|
||||
<stop stop-color="#F6F2FC"/>
|
||||
<stop offset="1" stop-color="#E5DDEE"/>
|
||||
</linearGradient>
|
||||
<linearGradient id="material" x1="31" y1="35" x2="96" y2="95" gradientUnits="userSpaceOnUse">
|
||||
<stop stop-color="#9170E2"/>
|
||||
<stop offset=".38" stop-color="#6D4AFF"/>
|
||||
<stop offset=".6" stop-color="#7044D1"/>
|
||||
<stop offset=".82" stop-color="#A66598"/>
|
||||
<stop offset="1" stop-color="#B56D51"/>
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<rect x="12" y="12" width="104" height="104" rx="27" fill="url(#face)"/>
|
||||
<rect x="12.75" y="12.75" width="102.5" height="102.5" rx="26.25"
|
||||
fill="none" stroke="#A18CB7" stroke-width="1.5"/>
|
||||
<g id="mark">
|
||||
<path d="M 43.32 33.92 H 64.94 C 73.4 33.92 80.92 36.74 86.56 42.38 L 96.9 52.72 C 103.48 59.3 103.48 68.7 96.9 75.28 L 86.56 85.62 C 80.92 91.26 73.4 94.08 64.94 94.08 H 43.32 C 38.15 94.08 33.92 89.85 33.92 84.68 V 75.28 H 47.08 V 79.04 C 47.08 80.074 47.926 80.92 48.96 80.92 H 64.94 C 69.64 80.92 73.4 79.04 77.16 75.28 L 85.62 66.82 C 87.218 65.222 87.218 62.778 85.62 61.18 L 77.16 52.72 C 73.4 48.96 69.64 47.08 64.94 47.08 H 48.96 C 47.926 47.08 47.08 47.926 47.08 48.96 V 52.72 H 33.92 V 43.32 C 33.92 38.15 38.15 33.92 43.32 33.92 Z" fill="url(#material)" fill-rule="nonzero"/>
|
||||
<path d="M 29.22 58.36 H 62.12 C 65.222 58.36 67.76 60.898 67.76 64 C 67.76 67.102 65.222 69.64 62.12 69.64 H 29.22 C 26.118 69.64 23.58 67.102 23.58 64 C 23.58 60.898 26.118 58.36 29.22 58.36 Z" fill="url(#material)" fill-rule="nonzero"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 2.0 KiB |
|
Before Width: | Height: | Size: 51 KiB After Width: | Height: | Size: 51 KiB |
|
Before Width: | Height: | Size: 137 KiB After Width: | Height: | Size: 138 KiB |
|
Before Width: | Height: | Size: 363 KiB After Width: | Height: | Size: 407 KiB |
@@ -1,156 +1,164 @@
|
||||
<svg width="1920" height="1080" viewBox="0 0 1920 1080" xmlns="http://www.w3.org/2000/svg">
|
||||
<defs>
|
||||
<linearGradient id="bg" x1="0" y1="0" x2="1920" y2="1080" gradientUnits="userSpaceOnUse">
|
||||
<stop offset="0" stop-color="#1A1240"/>
|
||||
<stop offset="1" stop-color="#0A0618"/>
|
||||
</linearGradient>
|
||||
<radialGradient id="glow1" cx="1390" cy="520" r="640" gradientUnits="userSpaceOnUse">
|
||||
<stop offset="0" stop-color="#6D4AFF" stop-opacity="0.55"/>
|
||||
<stop offset="0.5" stop-color="#6D4AFF" stop-opacity="0.15"/>
|
||||
<stop offset="1" stop-color="#6D4AFF" stop-opacity="0"/>
|
||||
</radialGradient>
|
||||
<radialGradient id="glow2" cx="160" cy="1080" r="700" gradientUnits="userSpaceOnUse">
|
||||
<stop offset="0" stop-color="#A855F7" stop-opacity="0.25"/>
|
||||
<stop offset="1" stop-color="#A855F7" stop-opacity="0"/>
|
||||
</radialGradient>
|
||||
<pattern id="dots" width="32" height="32" patternUnits="userSpaceOnUse">
|
||||
<circle cx="2" cy="2" r="1.6" fill="#FFFFFF"/>
|
||||
</pattern>
|
||||
<radialGradient id="dotfade" cx="1390" cy="520" r="900" gradientUnits="userSpaceOnUse">
|
||||
<stop offset="0" stop-color="#FFFFFF" stop-opacity="1"/>
|
||||
<stop offset="1" stop-color="#FFFFFF" stop-opacity="0"/>
|
||||
</radialGradient>
|
||||
<mask id="dotmask" maskUnits="userSpaceOnUse" x="0" y="0" width="1920" height="1080">
|
||||
<rect width="1920" height="1080" fill="url(#dotfade)"/>
|
||||
</mask>
|
||||
<linearGradient id="title2" x1="140" y1="0" x2="760" y2="0" gradientUnits="userSpaceOnUse">
|
||||
<stop offset="0" stop-color="#C9BBFF"/>
|
||||
<stop offset="1" stop-color="#8A6CFF"/>
|
||||
</linearGradient>
|
||||
|
||||
<!-- app logo -->
|
||||
<linearGradient id="pdl-face" x1="12" y1="12" x2="116" y2="112" gradientUnits="userSpaceOnUse">
|
||||
<stop offset="0" stop-color="#A48BFF"/>
|
||||
<stop offset="0.55" stop-color="#7552FF"/>
|
||||
<stop offset="1" stop-color="#5B36F2"/>
|
||||
</linearGradient>
|
||||
<linearGradient id="pdl-cloud" x1="0" y1="34" x2="0" y2="88" gradientUnits="userSpaceOnUse">
|
||||
<stop offset="0" stop-color="#FFFFFF"/>
|
||||
<stop offset="1" stop-color="#ECE6FF"/>
|
||||
</linearGradient>
|
||||
<mask id="pdl-cut" maskUnits="userSpaceOnUse" x="0" y="0" width="128" height="128">
|
||||
<g fill="#FFFFFF">
|
||||
<circle cx="66" cy="57" r="23"/>
|
||||
<circle cx="42" cy="68" r="16"/>
|
||||
<circle cx="88" cy="69" r="15"/>
|
||||
<rect x="26" y="68" width="77" height="20" rx="10"/>
|
||||
</g>
|
||||
<g stroke="#000000" stroke-width="7.5" stroke-linecap="round" stroke-linejoin="round" fill="none">
|
||||
<path d="M64 49v26"/>
|
||||
<path d="M54.5 65.5l9.5 9.5 9.5-9.5"/>
|
||||
</g>
|
||||
</mask>
|
||||
<filter id="logoshadow" x="-50%" y="-50%" width="200%" height="200%">
|
||||
<feGaussianBlur stdDeviation="6"/>
|
||||
</filter>
|
||||
<filter id="chipshadow" x="-50%" y="-50%" width="200%" height="200%">
|
||||
<feGaussianBlur stdDeviation="14"/>
|
||||
</filter>
|
||||
</defs>
|
||||
|
||||
<!-- background -->
|
||||
<rect width="1920" height="1080" fill="url(#bg)"/>
|
||||
<rect width="1920" height="1080" fill="url(#glow2)"/>
|
||||
<rect width="1920" height="1080" fill="url(#glow1)"/>
|
||||
<rect width="1920" height="1080" fill="url(#dots)" opacity="0.07" mask="url(#dotmask)"/>
|
||||
|
||||
<!-- orbit rings -->
|
||||
<g fill="none" stroke="#FFFFFF">
|
||||
<circle cx="1390" cy="520" r="300" stroke-opacity="0.10" stroke-width="2"/>
|
||||
<circle cx="1390" cy="520" r="420" stroke-opacity="0.06" stroke-width="2" stroke-dasharray="4 14" stroke-linecap="round"/>
|
||||
</g>
|
||||
|
||||
<!-- logo, 128 -> 384 -->
|
||||
<g transform="translate(1198 328) scale(3)">
|
||||
<rect x="16" y="24" width="96" height="92" rx="24" fill="#2A1080" opacity="0.8" filter="url(#logoshadow)"/>
|
||||
<rect x="12" y="16" width="104" height="100" rx="26" fill="#4424C0"/>
|
||||
<rect x="12" y="12" width="104" height="100" rx="26" fill="url(#pdl-face)"/>
|
||||
<rect x="12.5" y="12.5" width="103" height="99" rx="25.5" fill="none" stroke="#FFFFFF" stroke-opacity="0.2"/>
|
||||
<rect y="3" width="128" height="128" fill="#2E1596" fill-opacity="0.3" mask="url(#pdl-cut)"/>
|
||||
<rect width="128" height="128" fill="url(#pdl-cloud)" mask="url(#pdl-cut)"/>
|
||||
</g>
|
||||
|
||||
<!-- feature chips around the logo -->
|
||||
<g font-family="Adwaita Sans" font-size="26" font-weight="600" fill="#FFFFFF">
|
||||
<!-- folder, top left -->
|
||||
<g transform="translate(1000 200)">
|
||||
<rect x="0" y="10" width="236" height="76" rx="22" fill="#000000" opacity="0.35" filter="url(#chipshadow)"/>
|
||||
<rect x="0" y="0" width="236" height="76" rx="22" fill="#2A2058" fill-opacity="0.85" stroke="#FFFFFF" stroke-opacity="0.14" stroke-width="1.5"/>
|
||||
<g transform="translate(22 20)">
|
||||
<rect width="36" height="36" rx="10" fill="#6D4AFF"/>
|
||||
<path d="M8 13a2 2 0 0 1 2-2h5l2.5 2.5H26a2 2 0 0 1 2 2V25a2 2 0 0 1-2 2H10a2 2 0 0 1-2-2z" fill="#FFFFFF"/>
|
||||
</g>
|
||||
<text x="74" y="47">On demand</text>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Generated by scripts/render-branding.py; edit images/logo.svg. -->
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="1920" height="1080" viewBox="0 0 1920 1080">
|
||||
<defs>
|
||||
<linearGradient id="bg" x1="0" y1="0" x2="1920" y2="1080" gradientUnits="userSpaceOnUse">
|
||||
<stop offset="0" stop-color="#1A1240" />
|
||||
<stop offset="1" stop-color="#0A0618" />
|
||||
</linearGradient>
|
||||
<radialGradient id="glow1" cx="1390" cy="520" r="640" gradientUnits="userSpaceOnUse">
|
||||
<stop offset="0" stop-color="#6D4AFF" stop-opacity="0.55" />
|
||||
<stop offset="0.5" stop-color="#6D4AFF" stop-opacity="0.15" />
|
||||
<stop offset="1" stop-color="#6D4AFF" stop-opacity="0" />
|
||||
</radialGradient>
|
||||
<radialGradient id="glow2" cx="160" cy="1080" r="700" gradientUnits="userSpaceOnUse">
|
||||
<stop offset="0" stop-color="#A855F7" stop-opacity="0.25" />
|
||||
<stop offset="1" stop-color="#A855F7" stop-opacity="0" />
|
||||
</radialGradient>
|
||||
<pattern id="dots" width="32" height="32" patternUnits="userSpaceOnUse">
|
||||
<circle cx="2" cy="2" r="1.6" fill="#FFFFFF" />
|
||||
</pattern>
|
||||
<radialGradient id="dotfade" cx="1390" cy="520" r="900" gradientUnits="userSpaceOnUse">
|
||||
<stop offset="0" stop-color="#FFFFFF" stop-opacity="1" />
|
||||
<stop offset="1" stop-color="#FFFFFF" stop-opacity="0" />
|
||||
</radialGradient>
|
||||
<mask id="dotmask" maskUnits="userSpaceOnUse" x="0" y="0" width="1920" height="1080">
|
||||
<rect width="1920" height="1080" fill="url(#dotfade)" />
|
||||
</mask>
|
||||
<linearGradient id="title2" x1="140" y1="0" x2="760" y2="0" gradientUnits="userSpaceOnUse">
|
||||
<stop offset="0" stop-color="#C9BBFF" />
|
||||
<stop offset="1" stop-color="#8A6CFF" />
|
||||
</linearGradient>
|
||||
<filter id="chipshadow" x="-50%" y="-50%" width="200%" height="200%">
|
||||
<feGaussianBlur stdDeviation="14" />
|
||||
</filter>
|
||||
</defs>
|
||||
<rect width="1920" height="1080" fill="url(#bg)" />
|
||||
<rect width="1920" height="1080" fill="url(#glow2)" />
|
||||
<rect width="1920" height="1080" fill="url(#glow1)" />
|
||||
<rect width="1920" height="1080" fill="url(#dots)" opacity="0.07" mask="url(#dotmask)" />
|
||||
<g fill="none" stroke="#FFFFFF">
|
||||
<circle cx="1390" cy="520" r="300" stroke-opacity="0.10" stroke-width="2" />
|
||||
<circle cx="1390" cy="520" r="420" stroke-opacity="0.06" stroke-width="2" stroke-dasharray="4 14" stroke-linecap="round" />
|
||||
</g>
|
||||
<!-- sync, top right -->
|
||||
<g transform="translate(1590 290)">
|
||||
<rect x="0" y="10" width="164" height="76" rx="22" fill="#000000" opacity="0.35" filter="url(#chipshadow)"/>
|
||||
<rect x="0" y="0" width="164" height="76" rx="22" fill="#2A2058" fill-opacity="0.85" stroke="#FFFFFF" stroke-opacity="0.14" stroke-width="1.5"/>
|
||||
<g transform="translate(22 20)">
|
||||
<rect width="36" height="36" rx="10" fill="#1EA885"/>
|
||||
<g fill="none" stroke="#FFFFFF" stroke-width="2.6" stroke-linecap="round" stroke-linejoin="round">
|
||||
<path d="M26 15a8.5 8.5 0 0 0-15-2"/>
|
||||
<path d="M10 9v4.5h4.5"/>
|
||||
<path d="M10 21a8.5 8.5 0 0 0 15 2"/>
|
||||
<path d="M26 27v-4.5h-4.5"/>
|
||||
<g id="app-logo" transform="translate(1198 328) scale(1.5)">
|
||||
<defs>
|
||||
<linearGradient id="drive-face" x1="36" y1="212" x2="220" y2="54" gradientUnits="userSpaceOnUse">
|
||||
<stop stop-color="#6240DA" />
|
||||
<stop offset=".52" stop-color="#8056EF" />
|
||||
<stop offset="1" stop-color="#D58BDF" />
|
||||
</linearGradient>
|
||||
<linearGradient id="drive-rear" x1="26" y1="42" x2="218" y2="220" gradientUnits="userSpaceOnUse">
|
||||
<stop stop-color="#8C68EE" />
|
||||
<stop offset="1" stop-color="#5533B5" />
|
||||
</linearGradient>
|
||||
<linearGradient id="drive-paper" x1="60" y1="80" x2="180" y2="162" gradientUnits="userSpaceOnUse">
|
||||
<stop stop-color="#E7DFFA" />
|
||||
<stop offset="1" stop-color="#BDA5EF" />
|
||||
</linearGradient>
|
||||
<linearGradient id="drive-copper" x1="32" y1="32" x2="232" y2="224" gradientUnits="userSpaceOnUse">
|
||||
<stop stop-color="#703E30" />
|
||||
<stop offset=".16" stop-color="#B47456" />
|
||||
<stop offset=".28" stop-color="#E6B296" />
|
||||
<stop offset=".32" stop-color="#F8D8C3" />
|
||||
<stop offset=".37" stop-color="#BB7C5A" />
|
||||
<stop offset=".56" stop-color="#8A4D36" />
|
||||
<stop offset=".69" stop-color="#D69B77" />
|
||||
<stop offset=".75" stop-color="#F2C9AA" />
|
||||
<stop offset=".81" stop-color="#B87956" />
|
||||
<stop offset="1" stop-color="#713F30" />
|
||||
</linearGradient>
|
||||
<linearGradient id="drive-sun" x1="172" y1="82" x2="201" y2="112" gradientUnits="userSpaceOnUse">
|
||||
<stop stop-color="#8D513A" />
|
||||
<stop offset=".33" stop-color="#DDA581" />
|
||||
<stop offset=".47" stop-color="#F7D8B8" />
|
||||
<stop offset=".53" stop-color="#D69B74" />
|
||||
<stop offset="1" stop-color="#925439" />
|
||||
</linearGradient>
|
||||
<linearGradient id="drive-mountain" x1="44" y1="148" x2="186" y2="218" gradientUnits="userSpaceOnUse">
|
||||
<stop stop-color="#D9C9FA" />
|
||||
<stop offset="1" stop-color="#A582E9" />
|
||||
</linearGradient>
|
||||
<linearGradient id="drive-far-mountain" x1="142" y1="152" x2="211" y2="216" gradientUnits="userSpaceOnUse">
|
||||
<stop stop-color="#E8B4EB" />
|
||||
<stop offset="1" stop-color="#BB7BD7" />
|
||||
</linearGradient>
|
||||
<clipPath id="drive-photo-clip">
|
||||
<rect x="28" y="54" width="194" height="172" rx="24" />
|
||||
</clipPath>
|
||||
</defs>
|
||||
<g id="mark">
|
||||
<path d="M48 48H91Q99 48 105 54L117 66Q123 72 132 72H208Q228 72 228 92V200Q228 220 208 220H48Q28 220 28 200V68Q28 48 48 48Z" fill="url(#drive-copper)" transform="translate(6 -6)" stroke="#7D4936" stroke-width=".8" stroke-linejoin="round" />
|
||||
<path d="M48 48H91Q99 48 105 54L117 66Q123 72 132 72H208Q228 72 228 92V200Q228 220 208 220H48Q28 220 28 200V68Q28 48 48 48Z" fill="url(#drive-rear)" stroke="#5E3CBD" stroke-width=".8" />
|
||||
<rect x="72" y="82" width="132" height="112" rx="10" fill="url(#drive-paper)" stroke="#EFE9FC" stroke-width="1" />
|
||||
<rect x="51" y="97" width="140" height="109" rx="10" fill="url(#drive-paper)" stroke="#EFE9FC" stroke-width="1" />
|
||||
<path d="M48 94H89Q97 94 103 100L115 112Q121 118 130 118H208Q228 118 228 138V206Q228 226 208 226H48Q28 226 28 206V114Q28 94 48 94Z" fill="url(#drive-copper)" transform="translate(6 -6)" stroke="#7D4936" stroke-width=".8" stroke-linejoin="round" />
|
||||
<path d="M48 94H89Q97 94 103 100L115 112Q121 118 130 118H208Q228 118 228 138V206Q228 226 208 226H48Q28 226 28 206V114Q28 94 48 94Z" fill="url(#drive-face)" stroke="#5936B7" stroke-width=".9" />
|
||||
<path d="M32 113Q32 98 48 98H89Q95 98 100 103L112 115Q120 122 130 122H208Q224 122 224 138" fill="none" stroke="#F3DDF9" stroke-opacity=".52" stroke-width="1.5" stroke-linecap="round" />
|
||||
</g>
|
||||
</g>
|
||||
<text x="74" y="47">Sync</text>
|
||||
</g>
|
||||
<!-- photos, bottom right -->
|
||||
<g transform="translate(1560 690)">
|
||||
<rect x="0" y="10" width="206" height="76" rx="22" fill="#000000" opacity="0.35" filter="url(#chipshadow)"/>
|
||||
<rect x="0" y="0" width="206" height="76" rx="22" fill="#2A2058" fill-opacity="0.85" stroke="#FFFFFF" stroke-opacity="0.14" stroke-width="1.5"/>
|
||||
<g transform="translate(22 20)">
|
||||
<rect width="36" height="36" rx="10" fill="#E8618C"/>
|
||||
<rect x="8" y="9" width="20" height="18" rx="3" fill="none" stroke="#FFFFFF" stroke-width="2.4"/>
|
||||
<circle cx="14" cy="15" r="2" fill="#FFFFFF"/>
|
||||
<path d="M9.5 25l6-6 4 4 3-3 4 4" fill="none" stroke="#FFFFFF" stroke-width="2.4" stroke-linejoin="round"/>
|
||||
</g>
|
||||
<text x="74" y="47">Photos</text>
|
||||
<g font-family="Adwaita Sans" font-size="26" font-weight="600" fill="#FFFFFF">
|
||||
<g transform="translate(1000 200)">
|
||||
<rect x="0" y="10" width="236" height="76" rx="22" fill="#000000" opacity="0.35" filter="url(#chipshadow)" />
|
||||
<rect x="0" y="0" width="236" height="76" rx="22" fill="#2A2058" fill-opacity="0.85" stroke="#FFFFFF" stroke-opacity="0.14" stroke-width="1.5" />
|
||||
<g transform="translate(22 20)">
|
||||
<rect width="36" height="36" rx="10" fill="#6D4AFF" />
|
||||
<path d="M8 13a2 2 0 0 1 2-2h5l2.5 2.5H26a2 2 0 0 1 2 2V25a2 2 0 0 1-2 2H10a2 2 0 0 1-2-2z" fill="#FFFFFF" />
|
||||
</g>
|
||||
<text x="74" y="47">On demand</text>
|
||||
</g>
|
||||
<g transform="translate(1590 290)">
|
||||
<rect x="0" y="10" width="164" height="76" rx="22" fill="#000000" opacity="0.35" filter="url(#chipshadow)" />
|
||||
<rect x="0" y="0" width="164" height="76" rx="22" fill="#2A2058" fill-opacity="0.85" stroke="#FFFFFF" stroke-opacity="0.14" stroke-width="1.5" />
|
||||
<g transform="translate(22 20)">
|
||||
<rect width="36" height="36" rx="10" fill="#1EA885" />
|
||||
<g fill="none" stroke="#FFFFFF" stroke-width="2.6" stroke-linecap="round" stroke-linejoin="round">
|
||||
<path d="M26 15a8.5 8.5 0 0 0-15-2" />
|
||||
<path d="M10 9v4.5h4.5" />
|
||||
<path d="M10 21a8.5 8.5 0 0 0 15 2" />
|
||||
<path d="M26 27v-4.5h-4.5" />
|
||||
</g>
|
||||
</g>
|
||||
<text x="74" y="47">Sync</text>
|
||||
</g>
|
||||
<g transform="translate(1560 690)">
|
||||
<rect x="0" y="10" width="206" height="76" rx="22" fill="#000000" opacity="0.35" filter="url(#chipshadow)" />
|
||||
<rect x="0" y="0" width="206" height="76" rx="22" fill="#2A2058" fill-opacity="0.85" stroke="#FFFFFF" stroke-opacity="0.14" stroke-width="1.5" />
|
||||
<g transform="translate(22 20)">
|
||||
<rect width="36" height="36" rx="10" fill="#E8618C" />
|
||||
<rect x="8" y="9" width="20" height="18" rx="3" fill="none" stroke="#FFFFFF" stroke-width="2.4" />
|
||||
<circle cx="14" cy="15" r="2" fill="#FFFFFF" />
|
||||
<path d="M9.5 25l6-6 4 4 3-3 4 4" fill="none" stroke="#FFFFFF" stroke-width="2.4" stroke-linejoin="round" />
|
||||
</g>
|
||||
<text x="74" y="47">Photos</text>
|
||||
</g>
|
||||
<g transform="translate(980 790)">
|
||||
<rect x="0" y="10" width="206" height="76" rx="22" fill="#000000" opacity="0.35" filter="url(#chipshadow)" />
|
||||
<rect x="0" y="0" width="206" height="76" rx="22" fill="#2A2058" fill-opacity="0.85" stroke="#FFFFFF" stroke-opacity="0.14" stroke-width="1.5" />
|
||||
<g transform="translate(22 20)">
|
||||
<rect width="36" height="36" rx="10" fill="#3B3F5C" />
|
||||
<path d="M9 12l6 6-6 6" fill="none" stroke="#FFFFFF" stroke-width="2.6" stroke-linecap="round" stroke-linejoin="round" />
|
||||
<path d="M18 25h9" stroke="#FFFFFF" stroke-width="2.6" stroke-linecap="round" />
|
||||
</g>
|
||||
<text x="74" y="48" font-family="JetBrainsMono NF" font-size="25" font-weight="700">pdfs</text>
|
||||
<text x="150" y="48" font-weight="500" fill="#B9B0D9">CLI</text>
|
||||
</g>
|
||||
</g>
|
||||
<!-- terminal, bottom left -->
|
||||
<g transform="translate(980 790)">
|
||||
<rect x="0" y="10" width="206" height="76" rx="22" fill="#000000" opacity="0.35" filter="url(#chipshadow)"/>
|
||||
<rect x="0" y="0" width="206" height="76" rx="22" fill="#2A2058" fill-opacity="0.85" stroke="#FFFFFF" stroke-opacity="0.14" stroke-width="1.5"/>
|
||||
<g transform="translate(22 20)">
|
||||
<rect width="36" height="36" rx="10" fill="#3B3F5C"/>
|
||||
<path d="M9 12l6 6-6 6" fill="none" stroke="#FFFFFF" stroke-width="2.6" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
<path d="M18 25h9" stroke="#FFFFFF" stroke-width="2.6" stroke-linecap="round"/>
|
||||
</g>
|
||||
<text x="74" y="48" font-family="JetBrainsMono NF" font-size="25" font-weight="700">pdfs</text>
|
||||
<text x="150" y="48" font-weight="500" fill="#B9B0D9">CLI</text>
|
||||
<g font-family="Adwaita Sans">
|
||||
<g transform="translate(140 292)">
|
||||
<rect width="410" height="48" rx="24" fill="#6D4AFF" fill-opacity="0.18" stroke="#8A6CFF" stroke-opacity="0.6" stroke-width="1.5" />
|
||||
<circle cx="28" cy="24" r="6" fill="#A48BFF" />
|
||||
<text x="46" y="32" font-size="21" font-weight="700" letter-spacing="2.4" fill="#D6CCFF">UNOFFICIAL · OPEN SOURCE</text>
|
||||
</g>
|
||||
<text x="134" y="478" font-size="124" font-weight="800" letter-spacing="-3" fill="#FFFFFF">Proton Drive</text>
|
||||
<text x="134" y="610" font-size="124" font-weight="800" letter-spacing="-3" fill="url(#title2)">for Linux</text>
|
||||
<text x="140" y="702" font-size="38" font-weight="400" fill="#B9B0D9">Your Drive as a folder, and a native GTK4 app.</text>
|
||||
<text x="140" y="752" font-size="38" font-weight="400" fill="#B9B0D9">No Electron.</text>
|
||||
</g>
|
||||
</g>
|
||||
|
||||
<!-- text block -->
|
||||
<g font-family="Adwaita Sans">
|
||||
<g transform="translate(140 292)">
|
||||
<rect width="410" height="48" rx="24" fill="#6D4AFF" fill-opacity="0.18" stroke="#8A6CFF" stroke-opacity="0.6" stroke-width="1.5"/>
|
||||
<circle cx="28" cy="24" r="6" fill="#A48BFF"/>
|
||||
<text x="46" y="32" font-size="21" font-weight="700" letter-spacing="2.4" fill="#D6CCFF">UNOFFICIAL · OPEN SOURCE</text>
|
||||
<g font-family="JetBrainsMono NF" font-size="24" fill="#8C83B0">
|
||||
<text x="140" y="968">github.com/narrrl/proton-drive-linux</text>
|
||||
</g>
|
||||
<g font-family="Adwaita Sans" font-size="22" fill="#6F6894">
|
||||
<text x="1780" y="968" text-anchor="end">Not affiliated with Proton AG</text>
|
||||
</g>
|
||||
<text x="134" y="478" font-size="124" font-weight="800" letter-spacing="-3" fill="#FFFFFF">Proton Drive</text>
|
||||
<text x="134" y="610" font-size="124" font-weight="800" letter-spacing="-3" fill="url(#title2)">for Linux</text>
|
||||
<text x="140" y="702" font-size="38" font-weight="400" fill="#B9B0D9">Your Drive as a folder, and a native GTK4 app.</text>
|
||||
<text x="140" y="752" font-size="38" font-weight="400" fill="#B9B0D9">No Electron.</text>
|
||||
</g>
|
||||
|
||||
<!-- footer -->
|
||||
<g font-family="JetBrainsMono NF" font-size="24" fill="#8C83B0">
|
||||
<text x="140" y="968">github.com/narrrl/proton-drive-linux</text>
|
||||
</g>
|
||||
<g font-family="Adwaita Sans" font-size="22" fill="#6F6894">
|
||||
<text x="1780" y="968" text-anchor="end">Not affiliated with Proton AG</text>
|
||||
</g>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 8.3 KiB After Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 115 KiB After Width: | Height: | Size: 115 KiB |
|
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 33 KiB |
@@ -1,36 +1,44 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg width="128" height="128" viewBox="0 0 128 128" fill="none" xmlns="http://www.w3.org/2000/svg" role="img" aria-label="Proton Drive for Linux">
|
||||
<defs>
|
||||
<linearGradient id="pdl-face" x1="12" y1="12" x2="116" y2="112" gradientUnits="userSpaceOnUse">
|
||||
<stop offset="0" stop-color="#A48BFF"/>
|
||||
<stop offset="0.55" stop-color="#7552FF"/>
|
||||
<stop offset="1" stop-color="#5B36F2"/>
|
||||
</linearGradient>
|
||||
<linearGradient id="pdl-cloud" x1="0" y1="34" x2="0" y2="88" gradientUnits="userSpaceOnUse">
|
||||
<stop offset="0" stop-color="#FFFFFF"/>
|
||||
<stop offset="1" stop-color="#ECE6FF"/>
|
||||
</linearGradient>
|
||||
<!-- the cloud, with the arrow cut out of it as negative space -->
|
||||
<mask id="pdl-cut" maskUnits="userSpaceOnUse" x="0" y="0" width="128" height="128">
|
||||
<g fill="#FFFFFF">
|
||||
<circle cx="66" cy="57" r="23"/>
|
||||
<circle cx="42" cy="68" r="16"/>
|
||||
<circle cx="88" cy="69" r="15"/>
|
||||
<rect x="26" y="68" width="77" height="20" rx="10"/>
|
||||
</g>
|
||||
<g stroke="#000000" stroke-width="7.5" stroke-linecap="round" stroke-linejoin="round">
|
||||
<path d="M64 49v26"/>
|
||||
<path d="M54.5 65.5l9.5 9.5 9.5-9.5"/>
|
||||
</g>
|
||||
</mask>
|
||||
</defs>
|
||||
|
||||
<!-- base: a rounded tile with a darker lower edge for depth -->
|
||||
<rect x="12" y="16" width="104" height="100" rx="26" fill="#4424C0"/>
|
||||
<rect x="12" y="12" width="104" height="100" rx="26" fill="url(#pdl-face)"/>
|
||||
<rect x="12.5" y="12.5" width="103" height="99" rx="25.5" stroke="#FFFFFF" stroke-opacity="0.2"/>
|
||||
|
||||
<!-- cloud shadow, then the cloud itself -->
|
||||
<rect y="3" width="128" height="128" fill="#2E1596" fill-opacity="0.3" mask="url(#pdl-cut)"/>
|
||||
<rect width="128" height="128" fill="url(#pdl-cloud)" mask="url(#pdl-cut)"/>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="256" height="256" viewBox="0 0 256 256" data-app="drive" role="img" aria-labelledby="drive-title drive-desc">
|
||||
<title id="drive-title">Proton Drive for Linux</title>
|
||||
<desc id="drive-desc">Frontal violet and pink vector icon with shallow metallic copper backing.</desc>
|
||||
<defs>
|
||||
<linearGradient id="drive-face" x1="36" y1="212" x2="220" y2="54" gradientUnits="userSpaceOnUse">
|
||||
<stop stop-color="#6240DA"/><stop offset=".52" stop-color="#8056EF"/><stop offset="1" stop-color="#D58BDF"/>
|
||||
</linearGradient>
|
||||
<linearGradient id="drive-rear" x1="26" y1="42" x2="218" y2="220" gradientUnits="userSpaceOnUse">
|
||||
<stop stop-color="#8C68EE"/><stop offset="1" stop-color="#5533B5"/>
|
||||
</linearGradient>
|
||||
<linearGradient id="drive-paper" x1="60" y1="80" x2="180" y2="162" gradientUnits="userSpaceOnUse">
|
||||
<stop stop-color="#E7DFFA"/><stop offset="1" stop-color="#BDA5EF"/>
|
||||
</linearGradient>
|
||||
<linearGradient id="drive-copper" x1="32" y1="32" x2="232" y2="224" gradientUnits="userSpaceOnUse">
|
||||
<stop stop-color="#703E30"/><stop offset=".16" stop-color="#B47456"/>
|
||||
<stop offset=".28" stop-color="#E6B296"/><stop offset=".32" stop-color="#F8D8C3"/>
|
||||
<stop offset=".37" stop-color="#BB7C5A"/><stop offset=".56" stop-color="#8A4D36"/>
|
||||
<stop offset=".69" stop-color="#D69B77"/><stop offset=".75" stop-color="#F2C9AA"/>
|
||||
<stop offset=".81" stop-color="#B87956"/><stop offset="1" stop-color="#713F30"/>
|
||||
</linearGradient>
|
||||
<linearGradient id="drive-sun" x1="172" y1="82" x2="201" y2="112" gradientUnits="userSpaceOnUse">
|
||||
<stop stop-color="#8D513A"/><stop offset=".33" stop-color="#DDA581"/>
|
||||
<stop offset=".47" stop-color="#F7D8B8"/><stop offset=".53" stop-color="#D69B74"/>
|
||||
<stop offset="1" stop-color="#925439"/>
|
||||
</linearGradient>
|
||||
<linearGradient id="drive-mountain" x1="44" y1="148" x2="186" y2="218" gradientUnits="userSpaceOnUse">
|
||||
<stop stop-color="#D9C9FA"/><stop offset="1" stop-color="#A582E9"/>
|
||||
</linearGradient>
|
||||
<linearGradient id="drive-far-mountain" x1="142" y1="152" x2="211" y2="216" gradientUnits="userSpaceOnUse">
|
||||
<stop stop-color="#E8B4EB"/><stop offset="1" stop-color="#BB7BD7"/>
|
||||
</linearGradient>
|
||||
<clipPath id="drive-photo-clip"><rect x="28" y="54" width="194" height="172" rx="24"/></clipPath>
|
||||
</defs>
|
||||
<!-- Canonical vector artwork; regenerate platform assets with scripts/render-branding.py. -->
|
||||
<g id="mark">
|
||||
<path d="M48 48H91Q99 48 105 54L117 66Q123 72 132 72H208Q228 72 228 92V200Q228 220 208 220H48Q28 220 28 200V68Q28 48 48 48Z" fill="url(#drive-copper)" transform="translate(6 -6)" stroke="#7D4936" stroke-width=".8" stroke-linejoin="round"/>
|
||||
<path d="M48 48H91Q99 48 105 54L117 66Q123 72 132 72H208Q228 72 228 92V200Q228 220 208 220H48Q28 220 28 200V68Q28 48 48 48Z" fill="url(#drive-rear)" stroke="#5E3CBD" stroke-width=".8"/>
|
||||
<rect x="72" y="82" width="132" height="112" rx="10" fill="url(#drive-paper)" stroke="#EFE9FC" stroke-width="1"/>
|
||||
<rect x="51" y="97" width="140" height="109" rx="10" fill="url(#drive-paper)" stroke="#EFE9FC" stroke-width="1"/>
|
||||
<path d="M48 94H89Q97 94 103 100L115 112Q121 118 130 118H208Q228 118 228 138V206Q228 226 208 226H48Q28 226 28 206V114Q28 94 48 94Z" fill="url(#drive-copper)" transform="translate(6 -6)" stroke="#7D4936" stroke-width=".8" stroke-linejoin="round"/>
|
||||
<path d="M48 94H89Q97 94 103 100L115 112Q121 118 130 118H208Q228 118 228 138V206Q228 226 208 226H48Q28 226 28 206V114Q28 94 48 94Z" fill="url(#drive-face)" stroke="#5936B7" stroke-width=".9"/>
|
||||
<path d="M32 113Q32 98 48 98H89Q95 98 100 103L112 115Q120 122 130 122H208Q224 122 224 138" fill="none" stroke="#F3DDF9" stroke-opacity=".52" stroke-width="1.5" stroke-linecap="round"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 3.6 KiB |
|
Before Width: | Height: | Size: 1.6 MiB After Width: | Height: | Size: 1.6 MiB |
|
Before Width: | Height: | Size: 283 KiB After Width: | Height: | Size: 283 KiB |
|
Before Width: | Height: | Size: 36 KiB After Width: | Height: | Size: 36 KiB |
|
Before Width: | Height: | Size: 96 KiB After Width: | Height: | Size: 96 KiB |
|
Before Width: | Height: | Size: 69 KiB After Width: | Height: | Size: 97 KiB |
@@ -9,13 +9,13 @@
|
||||
# Build + install: cd packaging && makepkg -fi
|
||||
|
||||
pkgname=proton-drive-linux
|
||||
pkgver=3.8.0
|
||||
pkgver=3.9.0
|
||||
pkgrel=1
|
||||
pkgdesc="Unofficial Proton Drive client for Linux: files-on-demand FUSE mount, CLI, GTK4 app + tray"
|
||||
arch=('x86_64')
|
||||
url="https://proton-drive.narl.io"
|
||||
license=('MIT')
|
||||
depends=('fuse3' 'gtk4' 'libadwaita' 'webkitgtk-6.0' 'perl-image-exiftool')
|
||||
depends=('fuse3' 'polkit' 'gtk4' 'libadwaita' 'webkitgtk-6.0' 'perl-image-exiftool')
|
||||
makedepends=('cargo' 'git' 'gettext')
|
||||
provides=('pdfs')
|
||||
# Files-on-demand mount + keyring need these at runtime.
|
||||
@@ -77,6 +77,9 @@ package() {
|
||||
install -Dm644 "packaging/proton-drive.service" \
|
||||
"$pkgdir/usr/lib/systemd/user/proton-drive.service"
|
||||
|
||||
install -Dm644 "packaging/io.narl.proton-drive-linux.policy" \
|
||||
"$pkgdir/usr/share/polkit-1/actions/io.narl.proton-drive-linux.policy"
|
||||
|
||||
# Translations: compiled from po/ into /usr/share/locale.
|
||||
po/build.sh "$pkgdir/usr/share/locale"
|
||||
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
pkgbase = proton-drive-for-linux-bin
|
||||
pkgdesc = Unofficial Proton Drive client: FUSE files-on-demand mount, CLI, GTK4 app, tray (binaries)
|
||||
pkgver = 3.7.0
|
||||
pkgver = 3.8.0
|
||||
pkgrel = 1
|
||||
url = https://proton-drive.narl.io
|
||||
install = proton-drive.install
|
||||
arch = x86_64
|
||||
license = MIT
|
||||
depends = fuse3
|
||||
depends = polkit
|
||||
depends = gtk4
|
||||
depends = libadwaita
|
||||
depends = webkitgtk-6.0
|
||||
@@ -22,25 +23,15 @@ pkgbase = proton-drive-for-linux-bin
|
||||
optdepends = xdg-utils: "Open folder" action in the tray menu
|
||||
optdepends = fzf: search-as-you-type launcher (pdfs-prompt --fzf)
|
||||
optdepends = foot: terminal that hosts pdfs-prompt --fzf when started from a keybinding
|
||||
provides = proton-drive-for-linux=3.7.0
|
||||
provides = proton-drive-linux=3.7.0
|
||||
provides = proton-drive-for-linux=3.8.0
|
||||
provides = proton-drive-linux=3.8.0
|
||||
provides = pdfs
|
||||
conflicts = proton-drive-linux
|
||||
conflicts = proton-drive-for-linux
|
||||
conflicts = proton-drive-for-linux-git
|
||||
options = !strip
|
||||
options = !debug
|
||||
source = proton-drive-linux-3.7.0-x86_64.tar.gz::https://github.com/narrrl/proton-drive-linux/releases/download/v3.7.0/proton-drive-linux-3.7.0-x86_64.tar.gz
|
||||
source = io.narl.proton-drive-linux-3.7.0.desktop::https://raw.githubusercontent.com/narrrl/proton-drive-linux/v3.7.0/packaging/io.narl.proton-drive-linux.desktop
|
||||
source = io.narl.proton-drive-linux-tray-3.7.0.desktop::https://raw.githubusercontent.com/narrrl/proton-drive-linux/v3.7.0/packaging/io.narl.proton-drive-linux-tray.desktop
|
||||
source = io.narl.proton-drive-linux-3.7.0.svg::https://raw.githubusercontent.com/narrrl/proton-drive-linux/v3.7.0/packaging/io.narl.proton-drive-linux.svg
|
||||
source = proton-drive-3.7.0.service::https://raw.githubusercontent.com/narrrl/proton-drive-linux/v3.7.0/packaging/proton-drive.service
|
||||
source = LICENSE-3.7.0::https://raw.githubusercontent.com/narrrl/proton-drive-linux/v3.7.0/LICENSE
|
||||
sha256sums = 3f0d16c19b10b30e3f181e3c7fb439f0a8c38980e8ab7a4a96ae6596b349787c
|
||||
sha256sums = d190d6771fff0b975271fb62fd3fb0fa8bbf17d7278c10853c18557855b0c123
|
||||
sha256sums = 1d95e250370220e3bb6aead6ce34d1d6cc759f42c4803b75f1667e78ff47c6c0
|
||||
sha256sums = e598a93c2715c3a9fdc7fb937902083d4a1135e8fbdfe6fe7e37f0383ebbd828
|
||||
sha256sums = 44c25dca6e759c46fca50b58099aa6194abe78293dee07d971bbbce0ff3ca58f
|
||||
sha256sums = 02c419e7f9af08dda720e4f852f3e57cf5a69e192605440f750e9d244fa2817c
|
||||
source = proton-drive-linux-3.8.0-x86_64.tar.gz::https://github.com/narrrl/proton-drive-linux/releases/download/v3.8.0/proton-drive-linux-3.8.0-x86_64.tar.gz
|
||||
sha256sums = 99348fbf9121624701ae43e52776e5d1c469ff5cd5e52cd216bf8cb969e0bab2
|
||||
|
||||
pkgname = proton-drive-for-linux-bin
|
||||
@@ -1,14 +1,14 @@
|
||||
# Maintainer: Nils Pukropp <contact@narl.io>
|
||||
|
||||
pkgname=proton-drive-for-linux-bin
|
||||
pkgver=3.7.0
|
||||
pkgver=3.8.0
|
||||
pkgrel=1
|
||||
pkgdesc="Unofficial Proton Drive client: FUSE files-on-demand mount, CLI, GTK4 app, tray (binaries)"
|
||||
arch=('x86_64')
|
||||
url="https://proton-drive.narl.io"
|
||||
_repo="https://github.com/narrrl/proton-drive-linux"
|
||||
license=('MIT')
|
||||
depends=('fuse3' 'gtk4' 'libadwaita' 'webkitgtk-6.0' 'dbus' 'gcc-libs' 'glibc'
|
||||
depends=('fuse3' 'polkit' 'gtk4' 'libadwaita' 'webkitgtk-6.0' 'dbus' 'gcc-libs' 'glibc'
|
||||
'hicolor-icon-theme')
|
||||
optdepends=('perl-image-exiftool: thumbnails for camera RAW files'
|
||||
'ffmpeg: video thumbnails'
|
||||
@@ -25,54 +25,37 @@ options=('!strip' '!debug')
|
||||
# Stops the running daemon before removal, so the mount stops mirroring deletes.
|
||||
install=proton-drive.install
|
||||
_tag="v$pkgver"
|
||||
_raw="https://raw.githubusercontent.com/narrrl/proton-drive-linux/$_tag"
|
||||
# The release tarball holds the four binaries only, so the desktop integration
|
||||
# files come straight from the tagged tree. Every one carries $pkgver in its
|
||||
# name: makepkg reuses a cached file of the same name, so an unversioned name
|
||||
# keeps the old copy after upstream changes it and fails the checksum.
|
||||
source=("proton-drive-linux-$pkgver-x86_64.tar.gz::$_repo/releases/download/$_tag/proton-drive-linux-$pkgver-x86_64.tar.gz"
|
||||
"io.narl.proton-drive-linux-$pkgver.desktop::$_raw/packaging/io.narl.proton-drive-linux.desktop"
|
||||
"io.narl.proton-drive-linux-tray-$pkgver.desktop::$_raw/packaging/io.narl.proton-drive-linux-tray.desktop"
|
||||
"io.narl.proton-drive-linux-$pkgver.svg::$_raw/packaging/io.narl.proton-drive-linux.svg"
|
||||
"proton-drive-$pkgver.service::$_raw/packaging/proton-drive.service"
|
||||
"LICENSE-$pkgver::$_raw/LICENSE")
|
||||
sha256sums=('3f0d16c19b10b30e3f181e3c7fb439f0a8c38980e8ab7a4a96ae6596b349787c'
|
||||
'd190d6771fff0b975271fb62fd3fb0fa8bbf17d7278c10853c18557855b0c123'
|
||||
'1d95e250370220e3bb6aead6ce34d1d6cc759f42c4803b75f1667e78ff47c6c0'
|
||||
'e598a93c2715c3a9fdc7fb937902083d4a1135e8fbdfe6fe7e37f0383ebbd828'
|
||||
'44c25dca6e759c46fca50b58099aa6194abe78293dee07d971bbbce0ff3ca58f'
|
||||
'02c419e7f9af08dda720e4f852f3e57cf5a69e192605440f750e9d244fa2817c')
|
||||
# The release tarball holds the binaries and everything installed around them
|
||||
# (desktop files, icon, user service, translations, completions) in a /usr-like
|
||||
# tree under one directory.
|
||||
source=("proton-drive-linux-$pkgver-x86_64.tar.gz::$_repo/releases/download/$_tag/proton-drive-linux-$pkgver-x86_64.tar.gz")
|
||||
sha256sums=('99348fbf9121624701ae43e52776e5d1c469ff5cd5e52cd216bf8cb969e0bab2')
|
||||
|
||||
package() {
|
||||
install -Dm755 "$srcdir/pdfs" "$pkgdir/usr/bin/pdfs"
|
||||
install -Dm755 "$srcdir/pdfs-tray" "$pkgdir/usr/bin/pdfs-tray"
|
||||
install -Dm755 "$srcdir/pdfs-app" "$pkgdir/usr/bin/pdfs-app"
|
||||
install -Dm755 "$srcdir/pdfs-prompt" "$pkgdir/usr/bin/pdfs-prompt"
|
||||
cd "$srcdir/proton-drive-linux-$pkgver-x86_64"
|
||||
local exe
|
||||
for exe in pdfs pdfs-tray pdfs-app pdfs-prompt; do
|
||||
install -Dm755 "bin/$exe" "$pkgdir/usr/bin/$exe"
|
||||
done
|
||||
|
||||
install -Dm644 "$srcdir/io.narl.proton-drive-linux-$pkgver.desktop" \
|
||||
install -Dm644 share/applications/io.narl.proton-drive-linux.desktop \
|
||||
"$pkgdir/usr/share/applications/io.narl.proton-drive-linux.desktop"
|
||||
install -Dm644 "$srcdir/io.narl.proton-drive-linux-tray-$pkgver.desktop" \
|
||||
install -Dm644 etc/xdg/autostart/io.narl.proton-drive-linux-tray.desktop \
|
||||
"$pkgdir/etc/xdg/autostart/io.narl.proton-drive-linux-tray.desktop"
|
||||
install -Dm644 "$srcdir/io.narl.proton-drive-linux-$pkgver.svg" \
|
||||
install -Dm644 share/icons/hicolor/scalable/apps/io.narl.proton-drive-linux.svg \
|
||||
"$pkgdir/usr/share/icons/hicolor/scalable/apps/io.narl.proton-drive-linux.svg"
|
||||
|
||||
# systemd user unit for the auto-mount daemon; enabled per user, not by pacman.
|
||||
install -Dm644 "$srcdir/proton-drive-$pkgver.service" \
|
||||
install -Dm644 lib/systemd/user/proton-drive.service \
|
||||
"$pkgdir/usr/lib/systemd/user/proton-drive.service"
|
||||
|
||||
# Translations ship precompiled in the release tarball.
|
||||
# Translations and shell completion for bash, zsh and fish.
|
||||
install -dm755 "$pkgdir/usr/share"
|
||||
cp -r --no-preserve=ownership "$srcdir/locale" "$pkgdir/usr/share/locale"
|
||||
cp -r --no-preserve=ownership share/locale share/bash-completion share/zsh share/fish \
|
||||
"$pkgdir/usr/share/"
|
||||
|
||||
# Shell completion for bash, zsh and fish, written by the binary itself.
|
||||
local share="$pkgdir/usr/share"
|
||||
install -d "$share/bash-completion/completions" "$share/zsh/site-functions" \
|
||||
"$share/fish/vendor_completions.d"
|
||||
"$srcdir/pdfs" completions bash > "$share/bash-completion/completions/pdfs"
|
||||
"$srcdir/pdfs" completions zsh > "$share/zsh/site-functions/_pdfs"
|
||||
"$srcdir/pdfs" completions fish > "$share/fish/vendor_completions.d/pdfs.fish"
|
||||
|
||||
install -Dm644 "$srcdir/LICENSE-$pkgver" "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
|
||||
install -Dm644 share/licenses/proton-drive-linux/LICENSE \
|
||||
"$pkgdir/usr/share/licenses/$pkgname/LICENSE"
|
||||
|
||||
# pacman brings new releases, so the app never checks for them itself.
|
||||
install -Dm644 /dev/null "$pkgdir/usr/share/proton-drive-linux/managed-updates"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
pkgbase = proton-drive-for-linux-git
|
||||
pkgdesc = Unofficial Proton Drive client: FUSE files-on-demand mount, CLI, GTK4 app, tray (git)
|
||||
pkgver = 3.7.0.r0.g7ab14bb
|
||||
pkgver = 3.8.0.r0.g6fa91e8
|
||||
pkgrel = 1
|
||||
url = https://proton-drive.narl.io
|
||||
install = proton-drive.install
|
||||
@@ -10,6 +10,7 @@ pkgbase = proton-drive-for-linux-git
|
||||
makedepends = git
|
||||
makedepends = gettext
|
||||
depends = fuse3
|
||||
depends = polkit
|
||||
depends = gtk4
|
||||
depends = libadwaita
|
||||
depends = webkitgtk-6.0
|
||||
@@ -25,8 +26,8 @@ pkgbase = proton-drive-for-linux-git
|
||||
optdepends = xdg-utils: "Open folder" action in the tray menu
|
||||
optdepends = fzf: search-as-you-type launcher (pdfs-prompt --fzf)
|
||||
optdepends = foot: terminal that hosts pdfs-prompt --fzf when started from a keybinding
|
||||
provides = proton-drive-for-linux=3.7.0.r0.g7ab14bb
|
||||
provides = proton-drive-linux=3.7.0.r0.g7ab14bb
|
||||
provides = proton-drive-for-linux=3.8.0.r0.g6fa91e8
|
||||
provides = proton-drive-linux=3.8.0.r0.g6fa91e8
|
||||
provides = pdfs
|
||||
conflicts = proton-drive-linux
|
||||
conflicts = proton-drive-for-linux
|
||||
|
||||