Skip to content

Commit 9277596

Browse files
authored
Merge branch 'nextcloud:main' into main
2 parents fd479e6 + 20eec4b commit 9277596

9 files changed

Lines changed: 45 additions & 25 deletions

File tree

Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ rand = { version = "0.8.5", features = ["small_rng"] }
2929
ahash = "0.8.12"
3030
flexi_logger = { version = "0.31.8", features = ["colors"] }
3131
tokio-stream = { version = "0.1.17", features = ["net"] }
32-
nextcloud-config-parser = "0.15.1"
32+
nextcloud-config-parser = "0.15.2"
3333
url = "2.5.4"
3434
clap = { version = "4.5.43", features = ["derive"] }
3535
sd-notify = { version = "0.5.0", optional = true }

appinfo/info.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<description><![CDATA[Push update support for desktop app.
1212
1313
Once the app is installed, the push binary needs to be setup. You can either use the setup wizard with `occ notify_push:setup` or see the [README](http://github.com/nextcloud/notify_push) for detailed setup instructions]]></description>
14-
<version>1.3.1</version>
14+
<version>1.3.3</version>
1515
<licence>agpl</licence>
1616
<author>Robin Appelman</author>
1717
<namespace>NotifyPush</namespace>
@@ -27,7 +27,7 @@ Once the app is installed, the push binary needs to be setup. You can either use
2727
<bugs>https://github.com/nextcloud/notify_push/issues</bugs>
2828

2929
<dependencies>
30-
<nextcloud min-version="29" max-version="33"/>
30+
<nextcloud min-version="30" max-version="34"/>
3131
</dependencies>
3232

3333
<repair-steps>

flake.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
};
2828
lib = pkgs.lib;
2929

30-
hostTarget = pkgs.hostPlatform.config;
30+
hostTarget = pkgs.stdenv.hostPlatform.config;
3131
targets = [
3232
"x86_64-unknown-linux-musl"
3333
"i686-unknown-linux-musl"

lib/Listener.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use OCP\Notification\IDismissableNotifier;
2323
use OCP\Notification\INotification;
2424
use OCP\Notification\INotifier;
25+
use OCP\Notification\UnknownNotificationException;
2526
use OCP\Share\Events\ShareCreatedEvent;
2627
use OCP\Share\IShare;
2728

@@ -102,7 +103,7 @@ public function getName(): string {
102103
}
103104

104105
public function prepare(INotification $notification, string $languageCode): INotification {
105-
throw new \InvalidArgumentException();
106+
throw new UnknownNotificationException();
106107
}
107108

108109
public function dismissNotification(INotification $notification): void {

psalm.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
99
xmlns="https://getpsalm.org/schema/config"
1010
xsi:schemaLocation="https://getpsalm.org/schema/config https://getpsalm.org/schema/config"
11-
phpVersion="8.0"
11+
phpVersion="8.1"
1212
>
1313
<projectFiles>
1414
<directory name="lib"/>

src/config.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use sqlx::any::AnyConnectOptions;
2020
use std::convert::{TryFrom, TryInto};
2121
use std::env::var;
2222
use std::fmt::{Debug, Display, Formatter};
23-
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
23+
use std::net::{IpAddr, Ipv6Addr, SocketAddr};
2424
use std::path::{Path, PathBuf};
2525
use std::str::FromStr;
2626

@@ -183,9 +183,7 @@ impl TryFrom<PartialConfig> for Config {
183183
let bind = match config.socket {
184184
Some(socket) => Bind::Unix(socket, socket_permissions),
185185
None => {
186-
let ip = config
187-
.bind
188-
.unwrap_or_else(|| IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)));
186+
let ip = config.bind.unwrap_or(IpAddr::V6(Ipv6Addr::UNSPECIFIED));
189187
let port = config.port.unwrap_or(7867);
190188
Bind::Tcp((ip, port).into())
191189
}
@@ -194,9 +192,7 @@ impl TryFrom<PartialConfig> for Config {
194192
let metrics_bind = match (config.metrics_socket, config.metrics_port) {
195193
(Some(socket), _) => Some(Bind::Unix(socket, socket_permissions)),
196194
(None, Some(port)) => {
197-
let ip = config
198-
.bind
199-
.unwrap_or_else(|| IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)));
195+
let ip = config.bind.unwrap_or(IpAddr::V6(Ipv6Addr::UNSPECIFIED));
200196
Some(Bind::Tcp((ip, port).into()))
201197
}
202198
_ => None,

src/connection.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ pub async fn handle_user_socket(
226226
// hack while warp only has opaque error types
227227
match formatted.as_str() {
228228
"WebSocket protocol error: Connection reset without closing handshake"
229+
| "Broken pipe (os error 32)"
229230
| "IO error: Connection reset by peer (os error 104)" => {
230231
log::debug!("websocket error: {e:#}")
231232
}
@@ -262,11 +263,13 @@ async fn socket_auth(
262263
let username_msg = read_socket_auth_message(rx).await?;
263264
let username = username_msg
264265
.to_str()
265-
.map_err(|_| AuthenticationError::InvalidMessage)?;
266+
.map_err(|_| AuthenticationError::InvalidMessage)?
267+
.trim();
266268
let password_msg = read_socket_auth_message(rx).await?;
267269
let password = password_msg
268270
.to_str()
269-
.map_err(|_| AuthenticationError::InvalidMessage)?;
271+
.map_err(|_| AuthenticationError::InvalidMessage)?
272+
.trim();
270273

271274
// cleanup all pre_auth tokens older than 15s
272275
let cutoff = Instant::now() - Duration::from_secs(15);

src/storage_mapping.rs

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use log::debug;
1313
use rand::{thread_rng, Rng};
1414
use sqlx::any::AnyConnectOptions;
1515
use sqlx::{query_as, Any, AnyPool, FromRow};
16+
use std::sync::atomic::{AtomicBool, Ordering};
1617
use std::time::Instant;
1718
use tokio::time::Duration;
1819

@@ -27,6 +28,7 @@ pub struct UserStorageAccess {
2728
struct CachedAccess {
2829
access: Vec<UserStorageAccess>,
2930
valid_till: Instant,
31+
updating: AtomicBool,
3032
}
3133

3234
impl CachedAccess {
@@ -36,11 +38,16 @@ impl CachedAccess {
3638
access,
3739
valid_till: Instant::now()
3840
+ Duration::from_millis(rng.gen_range((4 * 60 * 1000)..(5 * 60 * 1000))),
41+
updating: AtomicBool::new(false),
3942
}
4043
}
4144

4245
pub fn is_valid(&self) -> bool {
43-
self.valid_till > Instant::now()
46+
self.valid_till > Instant::now() || self.updating.load(Ordering::SeqCst)
47+
}
48+
49+
pub fn prepare_update(&self, value: bool) {
50+
self.updating.store(value, Ordering::SeqCst);
4451
}
4552
}
4653

@@ -71,14 +78,27 @@ impl StorageMapping {
7178
&self,
7279
storage: u32,
7380
) -> Result<Ref<'_, u32, CachedAccess>, DatabaseError> {
74-
if let Some(cached) = self.cache.get(&storage).filter(|cached| cached.is_valid()) {
75-
Ok(cached)
76-
} else {
77-
let users = self.load_storage_mapping(storage).await?;
81+
if let Some(cached) = self.cache.get(&storage) {
82+
if cached.is_valid() {
83+
return Ok(cached);
84+
}
85+
86+
cached.prepare_update(true);
87+
let users = self
88+
.load_storage_mapping(storage)
89+
.await
90+
.inspect_err(|_| cached.prepare_update(false))?;
7891

79-
self.cache.insert(storage, CachedAccess::new(users));
80-
Ok(self.cache.get(&storage).unwrap())
92+
drop(cached);
93+
let cached = CachedAccess::new(users);
94+
self.cache.insert(storage, cached);
95+
return Ok(self.cache.get(&storage).unwrap());
8196
}
97+
98+
let users = self.load_storage_mapping(storage).await?;
99+
100+
self.cache.insert(storage, CachedAccess::new(users));
101+
Ok(self.cache.get(&storage).unwrap())
82102
}
83103

84104
pub async fn get_users_for_storage_path(

0 commit comments

Comments
 (0)