зеркало из https://github.com/mozilla/sccache.git
refactor: Do read check first instead
Signed-off-by: Xuanwo <github@xuanwo.io>
This commit is contained in:
Родитель
f618a28157
Коммит
762f5c60b5
|
@ -392,13 +392,7 @@ impl Storage for opendal::Operator {
|
||||||
|
|
||||||
let path = ".sccache_check";
|
let path = ".sccache_check";
|
||||||
|
|
||||||
let can_write = match self.object(path).write("Hello, World!").await {
|
// Read is required, return error directly if we can't read .
|
||||||
Ok(_) => true,
|
|
||||||
Err(err) if err.kind() == ErrorKind::ObjectAlreadyExists => true,
|
|
||||||
Err(err) if err.kind() == ErrorKind::ObjectPermissionDenied => false,
|
|
||||||
Err(err) => bail!("cache storage failed to write: {:?}", err),
|
|
||||||
};
|
|
||||||
|
|
||||||
match self.object(path).read().await {
|
match self.object(path).read().await {
|
||||||
Ok(_) => (),
|
Ok(_) => (),
|
||||||
// Read not exist file with not found is ok.
|
// Read not exist file with not found is ok.
|
||||||
|
@ -406,6 +400,16 @@ impl Storage for opendal::Operator {
|
||||||
Err(err) => bail!("cache storage failed to read: {:?}", err),
|
Err(err) => bail!("cache storage failed to read: {:?}", err),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let can_write = match self.object(path).write("Hello, World!").await {
|
||||||
|
Ok(_) => true,
|
||||||
|
Err(err) if err.kind() == ErrorKind::ObjectAlreadyExists => true,
|
||||||
|
// Toralte all other write errors because we can do read as least.
|
||||||
|
Err(err) => {
|
||||||
|
warn!("storage write check failed: {err:?}");
|
||||||
|
false
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
if can_write {
|
if can_write {
|
||||||
Ok(CacheMode::ReadWrite)
|
Ok(CacheMode::ReadWrite)
|
||||||
} else {
|
} else {
|
||||||
|
|
Загрузка…
Ссылка в новой задаче