@@ -6,7 +6,6 @@ use chrono::{DateTime, Utc};
6
6
use sqlx:: any:: { AnyKind , AnyStatement , AnyTypeInfo } ;
7
7
use sqlx:: postgres:: types:: PgTimeTz ;
8
8
use sqlx:: { Postgres , Statement , Type } ;
9
- use std:: borrow:: Cow ;
10
9
use std:: io:: ErrorKind ;
11
10
use std:: path:: { Component , Path , PathBuf } ;
12
11
@@ -40,11 +39,7 @@ impl FileSystem {
40
39
since : DateTime < Utc > ,
41
40
priviledged : bool ,
42
41
) -> 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) ?;
48
43
let local_result = file_modified_since_local ( & local_path, since) . await ;
49
44
match ( local_result, & self . db_fs_queries ) {
50
45
( Ok ( modified) , _) => Ok ( modified) ,
@@ -80,11 +75,7 @@ impl FileSystem {
80
75
path : & Path ,
81
76
priviledged : bool ,
82
77
) -> 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) ?;
88
79
let local_result = tokio:: fs:: read ( & local_path) . await ;
89
80
match ( local_result, & self . db_fs_queries ) {
90
81
( Ok ( f) , _) => Ok ( f) ,
@@ -100,10 +91,10 @@ impl FileSystem {
100
91
}
101
92
}
102
93
103
- fn safe_local_path ( & self , path : & Path ) -> anyhow:: Result < PathBuf > {
94
+ fn safe_local_path ( & self , path : & Path , priviledged : bool ) -> anyhow:: Result < PathBuf > {
104
95
for ( i, component) in path. components ( ) . enumerate ( ) {
105
96
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" ) {
107
98
anyhow:: bail!( "Access to the sqlpage config directory is not allowed." ) ;
108
99
}
109
100
} else {
0 commit comments