Skip to content

Commit 6865677

Browse files
committed
add sync chown path method, update ci
1 parent 0c3224a commit 6865677

9 files changed

Lines changed: 77 additions & 28 deletions

File tree

.github/workflows/build.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737

3838
steps:
3939
- name: Checkout sources
40-
uses: actions/checkout@v4
40+
uses: actions/checkout@v6
4141

4242
- name: Install Rust toolchain
4343
uses: actions-rust-lang/setup-rust-toolchain@v1
@@ -63,7 +63,7 @@ jobs:
6363
cp "target/${{ matrix.target }}/release/$BIN_NAME" "dist/$BIN_NAME-${{ matrix.build }}"
6464
6565
- name: Upload binary artifact
66-
uses: actions/upload-artifact@v4
66+
uses: actions/upload-artifact@v7
6767
with:
6868
name: ${{ env.PROJECT_NAME }}-${{ matrix.build }}
6969
path: dist/${{ env.BIN_NAME }}-${{ matrix.build }}
@@ -80,7 +80,7 @@ jobs:
8080

8181
steps:
8282
- name: Checkout code
83-
uses: actions/checkout@v4
83+
uses: actions/checkout@v6
8484

8585
- name: Generate source SBOM
8686
uses: anchore/sbom-action@v0
@@ -91,18 +91,18 @@ jobs:
9191
upload-artifact: false
9292

9393
- name: Download all artifacts
94-
uses: actions/download-artifact@v4
94+
uses: actions/download-artifact@v8
9595
with:
9696
path: dist
9797

9898
- name: Set up QEMU
99-
uses: docker/setup-qemu-action@v2
99+
uses: docker/setup-qemu-action@v4
100100

101101
- name: Set up Docker Buildx
102-
uses: docker/setup-buildx-action@v2
102+
uses: docker/setup-buildx-action@v4
103103

104104
- name: Login to GitHub Container Registry
105-
uses: docker/login-action@v3
105+
uses: docker/login-action@v4
106106
with:
107107
registry: ghcr.io
108108
username: ${{ github.actor }}
@@ -124,7 +124,7 @@ jobs:
124124

125125
- name: Build & push multi-arch image (main)
126126
id: build
127-
uses: docker/build-push-action@v5
127+
uses: docker/build-push-action@v7
128128
with:
129129
context: .
130130
platforms: linux/amd64,linux/arm64,linux/riscv64,linux/ppc64le

.github/workflows/release.yml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818

1919
steps:
2020
- name: Checkout sources
21-
uses: actions/checkout@v4
21+
uses: actions/checkout@v6
2222

2323
- name: Generate source SBOM
2424
uses: anchore/sbom-action@v0
@@ -56,7 +56,7 @@ jobs:
5656

5757
steps:
5858
- name: Checkout sources
59-
uses: actions/checkout@v4
59+
uses: actions/checkout@v6
6060

6161
- name: Install Rust toolchain
6262
uses: actions-rust-lang/setup-rust-toolchain@v1
@@ -82,7 +82,7 @@ jobs:
8282
cp "target/${{ matrix.target }}/release/$BIN_NAME" "dist/$BIN_NAME-${{ matrix.build }}"
8383
8484
- name: Upload binary artifact
85-
uses: actions/upload-artifact@v4
85+
uses: actions/upload-artifact@v7
8686
with:
8787
name: ${{ env.PROJECT_NAME }}-${{ matrix.build }}
8888
path: dist/${{ env.BIN_NAME }}-${{ matrix.build }}
@@ -96,7 +96,7 @@ jobs:
9696

9797
steps:
9898
- name: Download artifacts
99-
uses: actions/download-artifact@v4
99+
uses: actions/download-artifact@v8
100100
with:
101101
path: artifacts
102102

@@ -138,27 +138,27 @@ jobs:
138138

139139
steps:
140140
- name: Checkout code
141-
uses: actions/checkout@v4
141+
uses: actions/checkout@v6
142142

143143
- name: Download source SBOM
144-
uses: actions/download-artifact@v4
144+
uses: actions/download-artifact@v8
145145
with:
146146
name: sbom-source.cyclonedx.json
147147
path: sbom
148148

149149
- name: Download all artifacts
150-
uses: actions/download-artifact@v4
150+
uses: actions/download-artifact@v8
151151
with:
152152
path: dist
153153

154154
- name: Set up QEMU
155-
uses: docker/setup-qemu-action@v2
155+
uses: docker/setup-qemu-action@v4
156156

157157
- name: Set up Docker Buildx
158-
uses: docker/setup-buildx-action@v2
158+
uses: docker/setup-buildx-action@v4
159159

160160
- name: Login to GitHub Container Registry
161-
uses: docker/login-action@v3
161+
uses: docker/login-action@v4
162162
with:
163163
registry: ghcr.io
164164
username: ${{ github.actor }}
@@ -197,7 +197,7 @@ jobs:
197197
198198
- name: Build & push multi-arch image
199199
id: build
200-
uses: docker/build-push-action@v5
200+
uses: docker/build-push-action@v7
201201
with:
202202
context: .
203203
platforms: linux/amd64,linux/arm64,linux/riscv64,linux/ppc64le

application/src/routes/api/servers/_server_/files/decompress.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ mod post {
154154
}
155155
}
156156

157-
server.filesystem.chown_path(&root).await?;
157+
server.filesystem.async_chown_path(&root).await?;
158158

159159
ApiResponse::new_serialized(Response {}).ok()
160160
} else {

application/src/server/filesystem/mod.rs

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1033,7 +1033,55 @@ impl Filesystem {
10331033
Ok(())
10341034
}
10351035

1036-
pub async fn chown_path(&self, path: impl AsRef<Path>) -> Result<(), anyhow::Error> {
1036+
pub fn chown_path(&self, path: impl AsRef<Path>) -> Result<(), anyhow::Error> {
1037+
if self.config.load().system.user.rootless.enabled {
1038+
return Ok(());
1039+
}
1040+
1041+
#[cfg(unix)]
1042+
{
1043+
use std::os::fd::AsFd;
1044+
1045+
let metadata = self.metadata(path.as_ref())?;
1046+
1047+
let owner_uid = rustix::fs::Uid::from_raw_unchecked(self.config.load().system.user.uid);
1048+
let owner_gid = rustix::fs::Gid::from_raw_unchecked(self.config.load().system.user.gid);
1049+
1050+
if crate::unlikely(path.as_ref() == Path::new("") || path.as_ref() == Path::new("/")) {
1051+
std::os::unix::fs::chown(
1052+
&self.base_path,
1053+
Some(owner_uid.as_raw()),
1054+
Some(owner_gid.as_raw()),
1055+
)?;
1056+
} else {
1057+
rustix::fs::chownat(
1058+
self.cap_filesystem.get_inner()?.as_fd(),
1059+
self.relative_path(path.as_ref()),
1060+
Some(owner_uid),
1061+
Some(owner_gid),
1062+
rustix::fs::AtFlags::SYMLINK_NOFOLLOW,
1063+
)?;
1064+
}
1065+
1066+
if metadata.is_dir() {
1067+
let mut directory = self.read_dir(path.as_ref())?;
1068+
1069+
while let Some(entry) = directory.next_entry() {
1070+
let path = entry?.1;
1071+
1072+
self.chown_path(path)?;
1073+
}
1074+
}
1075+
1076+
Ok(())
1077+
}
1078+
#[cfg(not(unix))]
1079+
{
1080+
Ok(())
1081+
}
1082+
}
1083+
1084+
pub async fn async_chown_path(&self, path: impl AsRef<Path>) -> Result<(), anyhow::Error> {
10371085
if self.config.load().system.user.rootless.enabled {
10381086
return Ok(());
10391087
}

application/src/server/filesystem/virtualfs/cap.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,8 @@ impl super::VirtualWritableFilesystem for VirtualCapFilesystem {
730730
}
731731

732732
if self.is_primary_server_fs {
733-
tokio::runtime::Handle::current().block_on(self.server.filesystem.chown_path(path))?;
733+
tokio::runtime::Handle::current()
734+
.block_on(self.server.filesystem.async_chown_path(path))?;
734735
}
735736

736737
Ok(())
@@ -753,7 +754,7 @@ impl super::VirtualWritableFilesystem for VirtualCapFilesystem {
753754
}
754755

755756
if self.is_primary_server_fs {
756-
self.server.filesystem.chown_path(path).await?;
757+
self.server.filesystem.async_chown_path(path).await?;
757758
}
758759

759760
Ok(())

application/src/server/filesystem/writer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl FileSystemWriter {
4747
.set_permissions(destination, permissions)?;
4848
}
4949

50-
tokio::runtime::Handle::current().block_on(server.filesystem.chown_path(destination))?;
50+
server.filesystem.chown_path(destination)?;
5151

5252
Ok(Self {
5353
server,
@@ -191,7 +191,7 @@ impl AsyncFileSystemWriter {
191191
.await?;
192192
}
193193

194-
server.filesystem.chown_path(destination).await?;
194+
server.filesystem.async_chown_path(destination).await?;
195195

196196
Ok(Self {
197197
server,

application/src/server/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,7 @@ impl Server {
10361036
"Ensuring file permissions are set correctly, this could take a few seconds...",
10371037
);
10381038

1039-
server.filesystem.chown_path(&server.filesystem.base_path).await?;
1039+
server.filesystem.async_chown_path(&server.filesystem.base_path).await?;
10401040
}
10411041

10421042
server.setup_container().await?;

application/src/server/schedule/actions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,7 @@ impl ScheduleAction {
776776
})
777777
.await;
778778

779-
if let Err(err) = server.filesystem.chown_path(&path).await {
779+
if let Err(err) = server.filesystem.async_chown_path(&path).await {
780780
tracing::error!(path = %path.display(), "failed to change ownership: {:?}", err);
781781

782782
return Err("failed to change ownership".into());

application/src/ssh/sftp/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ impl russh_sftp::server::Handler for SftpSession {
625625
return Err(StatusCode::NoSuchFile);
626626
}
627627

628-
if self.server.filesystem.chown_path(path).await.is_err() {
628+
if self.server.filesystem.async_chown_path(path).await.is_err() {
629629
return Err(StatusCode::Failure);
630630
}
631631
if let Some(permissions) = attrs.permissions

0 commit comments

Comments
 (0)