@@ -6,7 +6,6 @@ use chrono::{DateTime, Utc};
66use sqlx:: any:: { AnyKind , AnyStatement , AnyTypeInfo } ;
77use sqlx:: postgres:: types:: PgTimeTz ;
88use sqlx:: { Postgres , Statement , Type } ;
9- use std:: borrow:: Cow ;
109use std:: io:: ErrorKind ;
1110use std:: path:: { Component , Path , PathBuf } ;
1211
@@ -40,11 +39,7 @@ impl FileSystem {
4039 since : DateTime < Utc > ,
4140 priviledged : bool ,
4241 ) -> anyhow:: Result < bool > {
43- let local_path = if priviledged {
44- Cow :: Borrowed ( path)
45- } else {
46- Cow :: Owned ( self . safe_local_path ( path) ?)
47- } ;
42+ let local_path = self . safe_local_path ( path, priviledged) ?;
4843 let local_result = file_modified_since_local ( & local_path, since) . await ;
4944 match ( local_result, & self . db_fs_queries ) {
5045 ( Ok ( modified) , _) => Ok ( modified) ,
@@ -80,11 +75,7 @@ impl FileSystem {
8075 path : & Path ,
8176 priviledged : bool ,
8277 ) -> anyhow:: Result < Vec < u8 > > {
83- let local_path = if priviledged {
84- Cow :: Borrowed ( path)
85- } else {
86- Cow :: Owned ( self . safe_local_path ( path) ?)
87- } ;
78+ let local_path = self . safe_local_path ( path, priviledged) ?;
8879 let local_result = tokio:: fs:: read ( & local_path) . await ;
8980 match ( local_result, & self . db_fs_queries ) {
9081 ( Ok ( f) , _) => Ok ( f) ,
@@ -100,10 +91,10 @@ impl FileSystem {
10091 }
10192 }
10293
103- fn safe_local_path ( & self , path : & Path ) -> anyhow:: Result < PathBuf > {
94+ fn safe_local_path ( & self , path : & Path , priviledged : bool ) -> anyhow:: Result < PathBuf > {
10495 for ( i, component) in path. components ( ) . enumerate ( ) {
10596 if let Component :: Normal ( c) = component {
106- if c . eq_ignore_ascii_case ( "sqlpage" ) && i == 0 {
97+ if !priviledged && i == 0 && c . eq_ignore_ascii_case ( "sqlpage" ) {
10798 anyhow:: bail!( "Access to the sqlpage config directory is not allowed." ) ;
10899 }
109100 } else {
0 commit comments