From d7d93ff6f0f26a74e75b00a82fa335a78d33ad0c Mon Sep 17 00:00:00 2001 From: Lzzzt Date: Sun, 14 Jul 2024 10:35:40 +0800 Subject: [PATCH 1/5] refactor: move metadata logic to construct time Signed-off-by: Lzzzt --- core/src/layers/blocking.rs | 10 ++++++---- core/src/layers/complete.rs | 17 +++++++++-------- core/src/layers/immutable_index.rs | 16 +++++++++------- 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/core/src/layers/blocking.rs b/core/src/layers/blocking.rs index 8deb767e6c1f..11b4b092473a 100644 --- a/core/src/layers/blocking.rs +++ b/core/src/layers/blocking.rs @@ -146,8 +146,12 @@ impl Layer for BlockingLayer { type LayeredAccess = BlockingAccessor; fn layer(&self, inner: A) -> Self::LayeredAccess { + let mut meta = inner.info().as_ref().clone(); + meta.full_capability_mut().blocking = true; + BlockingAccessor { inner, + meta: meta.into(), handle: self.handle.clone(), } } @@ -156,7 +160,7 @@ impl Layer for BlockingLayer { #[derive(Clone, Debug)] pub struct BlockingAccessor { inner: A, - + meta: Arc, handle: Handle, } @@ -174,9 +178,7 @@ impl LayeredAccess for BlockingAccessor { } fn metadata(&self) -> Arc { - let mut meta = self.inner.info().as_ref().clone(); - meta.full_capability_mut().blocking = true; - meta.into() + self.meta.clone() } async fn create_dir(&self, path: &str, args: OpCreateDir) -> Result { diff --git a/core/src/layers/complete.rs b/core/src/layers/complete.rs index 17c0c6414a01..52eb514ce798 100644 --- a/core/src/layers/complete.rs +++ b/core/src/layers/complete.rs @@ -109,8 +109,15 @@ impl Layer for CompleteLayer { type LayeredAccess = CompleteAccessor; fn layer(&self, inner: A) -> Self::LayeredAccess { + let mut meta = inner.info().as_ref().clone(); + + let cap = meta.full_capability_mut(); + if cap.list && cap.write_can_empty { + cap.create_dir = true; + } + CompleteAccessor { - meta: inner.info(), + meta: meta.into(), inner: Arc::new(inner), } } @@ -376,14 +383,8 @@ impl LayeredAccess for CompleteAccessor { &self.inner } - // Todo: May move the logic to the implement of Layer::layer of CompleteAccessor fn metadata(&self) -> Arc { - let mut meta = (*self.meta).clone(); - let cap = meta.full_capability_mut(); - if cap.list && cap.write_can_empty { - cap.create_dir = true; - } - meta.into() + self.meta.clone() } async fn create_dir(&self, path: &str, args: OpCreateDir) -> Result { diff --git a/core/src/layers/immutable_index.rs b/core/src/layers/immutable_index.rs index 5e02472fab6a..c9300d16b005 100644 --- a/core/src/layers/immutable_index.rs +++ b/core/src/layers/immutable_index.rs @@ -74,8 +74,15 @@ impl Layer for ImmutableIndexLayer { type LayeredAccess = ImmutableIndexAccessor; fn layer(&self, inner: A) -> Self::LayeredAccess { + let mut meta = inner.info().as_ref().clone(); + + let cap = meta.full_capability_mut(); + cap.list = true; + cap.list_with_recursive = true; + ImmutableIndexAccessor { vec: self.vec.clone(), + meta: meta.into(), inner, } } @@ -84,6 +91,7 @@ impl Layer for ImmutableIndexLayer { #[derive(Debug, Clone)] pub struct ImmutableIndexAccessor { inner: A, + meta: Arc, vec: Vec, } @@ -150,13 +158,7 @@ impl LayeredAccess for ImmutableIndexAccessor { /// Add list capabilities for underlying storage services. fn metadata(&self) -> Arc { - let mut meta = (*self.inner.info()).clone(); - - let cap = meta.full_capability_mut(); - cap.list = true; - cap.list_with_recursive = true; - - meta.into() + self.meta.clone() } async fn read(&self, path: &str, args: OpRead) -> Result<(RpRead, Self::Reader)> { From 4d5ce9c155f2dd75003a9e88b235cfb672171603 Mon Sep 17 00:00:00 2001 From: Lzzzt Date: Sun, 14 Jul 2024 11:25:43 +0800 Subject: [PATCH 2/5] refactor: move metadata logic to construct time Signed-off-by: Lzzzt --- core/src/layers/blocking.rs | 2 +- core/src/layers/complete.rs | 2 +- core/src/layers/immutable_index.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/core/src/layers/blocking.rs b/core/src/layers/blocking.rs index 11b4b092473a..b192c4b32521 100644 --- a/core/src/layers/blocking.rs +++ b/core/src/layers/blocking.rs @@ -151,7 +151,7 @@ impl Layer for BlockingLayer { BlockingAccessor { inner, - meta: meta.into(), + meta: Arc::new(meta), handle: self.handle.clone(), } } diff --git a/core/src/layers/complete.rs b/core/src/layers/complete.rs index 52eb514ce798..610f313a6c86 100644 --- a/core/src/layers/complete.rs +++ b/core/src/layers/complete.rs @@ -117,7 +117,7 @@ impl Layer for CompleteLayer { } CompleteAccessor { - meta: meta.into(), + meta: Arc::new(meta), inner: Arc::new(inner), } } diff --git a/core/src/layers/immutable_index.rs b/core/src/layers/immutable_index.rs index c9300d16b005..130587f21ed9 100644 --- a/core/src/layers/immutable_index.rs +++ b/core/src/layers/immutable_index.rs @@ -82,7 +82,7 @@ impl Layer for ImmutableIndexLayer { ImmutableIndexAccessor { vec: self.vec.clone(), - meta: meta.into(), + meta: Arc::new(meta), inner, } } From a827612742500bbe7e9412c52920e8579072b9e5 Mon Sep 17 00:00:00 2001 From: Lzzzt Date: Sun, 14 Jul 2024 12:00:42 +0800 Subject: [PATCH 3/5] revert Signed-off-by: Lzzzt --- core/src/layers/complete.rs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/core/src/layers/complete.rs b/core/src/layers/complete.rs index 610f313a6c86..ae5f637787cc 100644 --- a/core/src/layers/complete.rs +++ b/core/src/layers/complete.rs @@ -20,6 +20,8 @@ use std::fmt::Debug; use std::fmt::Formatter; use std::sync::Arc; +use quick_xml::se; + use crate::raw::oio::FlatLister; use crate::raw::oio::PrefixLister; use crate::raw::*; @@ -109,15 +111,8 @@ impl Layer for CompleteLayer { type LayeredAccess = CompleteAccessor; fn layer(&self, inner: A) -> Self::LayeredAccess { - let mut meta = inner.info().as_ref().clone(); - - let cap = meta.full_capability_mut(); - if cap.list && cap.write_can_empty { - cap.create_dir = true; - } - CompleteAccessor { - meta: Arc::new(meta), + meta: inner.info(), inner: Arc::new(inner), } } @@ -383,8 +378,14 @@ impl LayeredAccess for CompleteAccessor { &self.inner } + // Todo: May move the logic to the implement of Layer::layer of CompleteAccessor fn metadata(&self) -> Arc { - self.meta.clone() + let mut meta = self.meta.as_ref().clone(); + let cap = meta.full_capability_mut(); + if cap.list && cap.write_can_empty { + cap.create_dir = true; + } + meta.into() } async fn create_dir(&self, path: &str, args: OpCreateDir) -> Result { From 91bb308ad55d70578a0f16683d756d08b337b069 Mon Sep 17 00:00:00 2001 From: Lzzzt Date: Sun, 14 Jul 2024 12:18:58 +0800 Subject: [PATCH 4/5] refactor: move metadata logic to construct time Signed-off-by: Lzzzt --- core/src/layers/complete.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/core/src/layers/complete.rs b/core/src/layers/complete.rs index ae5f637787cc..5e776b9ae23e 100644 --- a/core/src/layers/complete.rs +++ b/core/src/layers/complete.rs @@ -20,8 +20,6 @@ use std::fmt::Debug; use std::fmt::Formatter; use std::sync::Arc; -use quick_xml::se; - use crate::raw::oio::FlatLister; use crate::raw::oio::PrefixLister; use crate::raw::*; @@ -111,8 +109,15 @@ impl Layer for CompleteLayer { type LayeredAccess = CompleteAccessor; fn layer(&self, inner: A) -> Self::LayeredAccess { + let mut meta = inner.info().as_ref().clone(); + let cap = meta.full_capability_mut(); + + if cap.list && cap.write_can_empty { + cap.create_dir = true; + } + CompleteAccessor { - meta: inner.info(), + meta: meta.into(), inner: Arc::new(inner), } } From 38ae3ffccd101a630e41307212e96408c893ae40 Mon Sep 17 00:00:00 2001 From: Lzzzt Date: Tue, 16 Jul 2024 15:20:49 +0800 Subject: [PATCH 5/5] refactor: move metadata logic to construct time Signed-off-by: Lzzzt --- core/src/layers/complete.rs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/core/src/layers/complete.rs b/core/src/layers/complete.rs index 5e776b9ae23e..4808c4f29ef4 100644 --- a/core/src/layers/complete.rs +++ b/core/src/layers/complete.rs @@ -383,14 +383,8 @@ impl LayeredAccess for CompleteAccessor { &self.inner } - // Todo: May move the logic to the implement of Layer::layer of CompleteAccessor fn metadata(&self) -> Arc { - let mut meta = self.meta.as_ref().clone(); - let cap = meta.full_capability_mut(); - if cap.list && cap.write_can_empty { - cap.create_dir = true; - } - meta.into() + self.meta.clone() } async fn create_dir(&self, path: &str, args: OpCreateDir) -> Result {