Merge pull request #5186 from liubin/fix/5185

runtime-rs: use Path.is_file to check regular files
This commit is contained in:
Bin Liu 2022-09-26 12:33:47 +08:00 committed by GitHub
commit 5a98fb8d2b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,7 +7,6 @@
use std::{path::Path, sync::Arc}; use std::{path::Path, sync::Arc};
use anyhow::{anyhow, Context, Result}; use anyhow::{anyhow, Context, Result};
use nix::sys::stat::{stat, SFlag};
use super::Volume; use super::Volume;
use crate::share_fs::{ShareFs, ShareFsVolumeConfig}; use crate::share_fs::{ShareFs, ShareFsVolumeConfig};
@ -34,44 +33,24 @@ impl ShareFsVolume {
let mut volume = Self { mounts: vec![] }; let mut volume = Self { mounts: vec![] };
match share_fs { match share_fs {
None => { None => {
let mut need_copy = false; let src = match std::fs::canonicalize(&m.source) {
match stat(Path::new(&m.source)) {
Ok(stat) => {
// Ignore the mount if this is not a regular file (excludes
// directory, socket, device, ...) as it cannot be handled by
// a simple copy. But this should not be treated as an error,
// only as a limitation.
// golang implement:
// ModeType = ModeDir | ModeSymlink | ModeNamedPipe | ModeSocket |
// ModeDevice | ModeCharDevice | ModeIrregular
let file_type = SFlag::S_IFDIR
| SFlag::S_IFLNK
| SFlag::S_IFIFO
| SFlag::S_IFSOCK
| SFlag::S_IFCHR
| SFlag::S_IFREG;
if !file_type.contains(SFlag::from_bits_truncate(stat.st_mode)) {
debug!(
sl!(),
"Ignoring non-regular file as FS sharing not supported. mount: {:?}",
m
);
return Ok(volume);
}
if SFlag::from_bits_truncate(stat.st_mode) != SFlag::S_IFDIR {
need_copy = true;
}
}
Err(err) => { Err(err) => {
return Err(anyhow!(format!( return Err(anyhow!(format!(
"failed to stat file {} {:?}", "failed to canonicalize file {} {:?}",
&m.source, err &m.source, err
))); )))
} }
Ok(src) => src,
}; };
if need_copy { if src.is_file() {
// TODO: copy file // TODO: copy file
debug!(sl!(), "FIXME: copy file {}", &m.source);
} else {
debug!(
sl!(),
"Ignoring non-regular file as FS sharing not supported. mount: {:?}", m
);
} }
} }
Some(share_fs) => { Some(share_fs) => {