Skip to content

Commit c9f17ab

Browse files
committed
feat: hide dot files
1 parent a34ee97 commit c9f17ab

File tree

6 files changed

+44
-12
lines changed

6 files changed

+44
-12
lines changed

rsync-gateway/src/handler.rs

+16-3
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,12 @@ pub async fn main_handler(
6161

6262
let locale = select_locale(&accepted_language);
6363

64-
let namespace = &endpoint.namespace;
65-
let s3_prefix = &endpoint.s3_prefix;
64+
let Endpoint {
65+
namespace,
66+
s3_prefix,
67+
list_hidden,
68+
..
69+
} = &**endpoint;
6670
let Some(Revision {
6771
revision,
6872
generated_at,
@@ -84,7 +88,16 @@ pub async fn main_handler(
8488
let resolved = match cache
8589
.get_or_insert(
8690
&path,
87-
resolve(namespace, &path, revision, s3_prefix, &**db, &op).boxed_local(),
91+
resolve(
92+
namespace,
93+
&path,
94+
revision,
95+
s3_prefix,
96+
*list_hidden,
97+
&**db,
98+
&op,
99+
)
100+
.boxed_local(),
88101
)
89102
.await
90103
{

rsync-gateway/src/opts.rs

+4
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ pub struct Endpoint {
116116
/// But it must be unique across all endpoints.
117117
#[doku(example = "fedora")]
118118
pub namespace: String,
119+
/// Whether to list hidden files.
120+
#[serde(default)]
121+
#[doku(example = "false")]
122+
pub list_hidden: bool,
119123
}
120124

121125
fn de_trim_end_slash<'de, D>(de: D) -> Result<String, D::Error>

rsync-gateway/src/path_resolve.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,13 @@ pub async fn resolve<'a>(
4646
path: &[u8],
4747
revision: i32,
4848
s3_prefix: &str,
49+
list_hidden: bool,
4950
db: impl Acquire<'a, Database = Postgres> + Clone,
5051
op: &Operator,
5152
) -> Result<Resolved> {
5253
Ok(match realpath(path, revision, db.clone()).await {
5354
Ok(Target::Directory(path)) => {
54-
let resolved = resolve_listing(&path, revision, db).await?;
55+
let resolved = resolve_listing(&path, revision, list_hidden, db).await?;
5556
increment_counter!(COUNTER_RESOLVED_LISTING);
5657
resolved
5758
}
@@ -93,9 +94,10 @@ pub async fn resolve<'a>(
9394
async fn resolve_listing<'a>(
9495
path: &[u8],
9596
revision: i32,
97+
list_hidden: bool,
9698
db: impl Acquire<'a, Database = Postgres>,
9799
) -> Result<Resolved> {
98-
let mut entries = list_directory(path, revision, db).await?;
100+
let mut entries = list_directory(path, revision, list_hidden, db).await?;
99101
entries.shrink_to_fit(); // shrink as much as we can to reduce cache memory usage
100102
Ok(Resolved::Directory { entries })
101103
}

rsync-gateway/src/pg.rs

+18-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
use std::future::ready;
2+
13
use bstr::ByteSlice;
24
use chrono::{DateTime, Utc};
35
use eyre::Result;
6+
use futures::TryStreamExt;
47
use sqlx::postgres::types::PgInterval;
58
use sqlx::types::BigDecimal;
69
use sqlx::{Acquire, Postgres};
@@ -164,24 +167,33 @@ impl From<RawResolveEntry> for ListingEntry {
164167
pub async fn list_directory<'a>(
165168
path: &[u8],
166169
revision: i32,
170+
list_hidden: bool,
167171
db: impl Acquire<'a, Database = Postgres>,
168172
) -> Result<Vec<ListingEntry>> {
173+
let executor = &mut *db.acquire().await?;
169174
Ok(if path.is_empty() {
170175
sqlx::query_file_as!(RawResolveEntry, "../sqls/list_root.sql", revision)
171-
.map(Into::into)
172-
.fetch_all(&mut *db.acquire().await?)
173-
.await?
176+
.map(ListingEntry::from)
177+
.fetch(executor)
174178
} else {
175179
sqlx::query_file_as!(
176180
RawResolveEntry,
177181
"../sqls/list_directory.sql",
178182
path,
179183
revision
180184
)
181-
.map(Into::into)
182-
.fetch_all(&mut *db.acquire().await?)
183-
.await?
185+
.map(ListingEntry::from)
186+
.fetch(executor)
187+
}
188+
.try_filter(|entry| {
189+
ready(if list_hidden {
190+
true
191+
} else {
192+
!entry.filename.starts_with(b".")
193+
})
184194
})
195+
.try_collect()
196+
.await?)
185197
}
186198

187199
#[cfg(test)]

rsync-gateway/src/render.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use crate::templates::{
2525
};
2626

2727
impl Resolved {
28-
/// Render the resolved result to a HTTP response.
28+
/// Render the resolved result to an HTTP response.
2929
pub fn to_responder(
3030
&self,
3131
req_path: &[u8],

rsync-gateway/src/tests.rs

+1
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ mod db_required {
256256
s3_bucket: String::new(),
257257
s3_prefix: namespace.clone(),
258258
namespace: namespace.clone(),
259+
list_hidden: false
259260
},
260261
},
261262
};

0 commit comments

Comments
 (0)