summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-06-18 05:07:20 +0800
committer魏曹先生 <1992414357@qq.com>2026-06-18 05:07:20 +0800
commit669898193bebeadc975881bee496fe0239df76a0 (patch)
tree7e5067d9fe2444fd81f401bb25ec945e6f0642ec
parent961ee2eb342259398916dfe7458098f7c9297c11 (diff)
fix: reject nested bucket creation inside existing bucket spaces
-rw-r--r--rola-cli/locales/i18n_bucket_manager.toml4
-rw-r--r--rola-cli/src/bucket_mgr/creation.rs16
2 files changed, 19 insertions, 1 deletions
diff --git a/rola-cli/locales/i18n_bucket_manager.toml b/rola-cli/locales/i18n_bucket_manager.toml
index d7f0ffe..09fae75 100644
--- a/rola-cli/locales/i18n_bucket_manager.toml
+++ b/rola-cli/locales/i18n_bucket_manager.toml
@@ -11,6 +11,8 @@ Example: `rola bucket create <name>`
error_bucket_path_not_directory = "The path \"%{path}\" is not a directory!"
+error_bucket_nested = "Cannot create a nested Bucket directory inside an existing Bucket space"
+
[zh_CN]
created = "桶已被创建于 \"%{path}\""
@@ -23,3 +25,5 @@ error_bucket_path_not_provided = """
"""
error_bucket_path_not_directory = "路径 \"%{path}\" 不是一个目录!"
+
+error_bucket_nested = "无法在已有的桶内创建嵌套的桶目录"
diff --git a/rola-cli/src/bucket_mgr/creation.rs b/rola-cli/src/bucket_mgr/creation.rs
index 831a3e7..c363773 100644
--- a/rola-cli/src/bucket_mgr/creation.rs
+++ b/rola-cli/src/bucket_mgr/creation.rs
@@ -6,7 +6,7 @@ use mingling::{
res::ResExitCode,
};
use rorolala::bucket::{Bucket, NoProtocol};
-use space_system::{Space, SpaceError};
+use space_system::{Space, SpaceError, SpaceRoot, find_space_root_with};
use crate::{
Next, error::ErrorIo, locale::I18nBucketManager, res::current_dir::ResCurrentDir, tkr,
@@ -15,6 +15,7 @@ use crate::{
pub const EC_BUCKET_CREATE_DIR_NOT_EMPTY: i32 = 2400;
pub const EC_BUCKET_PATH_NOT_PROVIDED: i32 = 2401;
pub const EC_BUCKET_PATH_NOT_DIRECTORY: i32 = 2402;
+pub const EC_BUCKET_NESTED: i32 = 2403;
dispatcher!("bucket.init");
dispatcher!("bucket.create");
@@ -27,6 +28,7 @@ pack!(ResultBucketCreated = PathBuf);
pack!(ErrorDirectoryNotEmpty = PathBuf);
pack!(ErrorBucketPathNotProvided = ());
pack!(ErrorBucketPathNotDirectory = PathBuf);
+pack!(ErrorBucketPathNested = PathBuf);
#[chain]
pub fn handle_bucket_init(_args: EntryBucketInit, cwd: &mut ResCurrentDir) -> Next {
@@ -50,6 +52,12 @@ pub fn handle_bucket_create(args: EntryBucketCreate) -> Next {
#[chain]
pub fn handle_state_bucket_creation_precheck(create: StateBucketCreationPrecheck) -> Next {
let path = create.inner;
+
+ // Reject if already inside a Bucket space
+ if find_space_root_with(&path, &Bucket::<NoProtocol>::get_pattern()).is_ok() {
+ return ErrorBucketPathNested::new(path).to_render();
+ }
+
if path.exists() {
if !path.is_dir() {
return ErrorBucketPathNotDirectory::new(path).to_render();
@@ -117,3 +125,9 @@ pub fn render_error_bucket_path_not_directory(
r_println!("{}", I18nBucketManager::error_directory_not_empty().trim());
ec.exit_code = EC_BUCKET_PATH_NOT_DIRECTORY;
}
+
+#[renderer]
+pub fn render_error_bucket_path_nested(_err: ErrorBucketPathNested, ec: &mut ResExitCode) {
+ r_println!("{}", I18nBucketManager::error_bucket_nested().trim());
+ ec.exit_code = EC_BUCKET_NESTED;
+}