зеркало из 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 can_write = match self.object(path).write("Hello, World!").await {
|
||||
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),
|
||||
};
|
||||
|
||||
// Read is required, return error directly if we can't read .
|
||||
match self.object(path).read().await {
|
||||
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),
|
||||
};
|
||||
|
||||
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 {
|
||||
Ok(CacheMode::ReadWrite)
|
||||
} else {
|
||||
|
|
Загрузка…
Ссылка в новой задаче