diff --git a/rustfs/src/storage/options.rs b/rustfs/src/storage/options.rs index 7a9489b1..3a4e9928 100644 --- a/rustfs/src/storage/options.rs +++ b/rustfs/src/storage/options.rs @@ -52,7 +52,7 @@ pub async fn del_opts( opts.version_id = { if is_dir_object(object) && vid.is_none() { - Some(Uuid::nil().to_string()) + Some(Uuid::max().to_string()) } else { vid } @@ -91,7 +91,7 @@ pub async fn get_opts( opts.version_id = { if is_dir_object(object) && vid.is_none() { - Some(Uuid::nil().to_string()) + Some(Uuid::max().to_string()) } else { vid } @@ -133,7 +133,7 @@ pub async fn put_opts( opts.version_id = { if is_dir_object(object) && vid.is_none() { - Some(Uuid::nil().to_string()) + Some(Uuid::max().to_string()) } else { vid } @@ -273,7 +273,7 @@ mod tests { assert!(result.is_ok()); let opts = result.unwrap(); - assert_eq!(opts.version_id, Some(Uuid::nil().to_string())); + assert_eq!(opts.version_id, Some(Uuid::max().to_string())); } #[tokio::test] @@ -346,7 +346,7 @@ mod tests { assert!(result.is_ok()); let opts = result.unwrap(); - assert_eq!(opts.version_id, Some(Uuid::nil().to_string())); + assert_eq!(opts.version_id, Some(Uuid::max().to_string())); } #[tokio::test] @@ -390,7 +390,7 @@ mod tests { assert!(result.is_ok()); let opts = result.unwrap(); - assert_eq!(opts.version_id, Some(Uuid::nil().to_string())); + assert_eq!(opts.version_id, Some(Uuid::max().to_string())); } #[tokio::test] diff --git a/scripts/test/delete_xldir.md b/scripts/test/delete_xldir.md new file mode 100644 index 00000000..626fa82e --- /dev/null +++ b/scripts/test/delete_xldir.md @@ -0,0 +1,71 @@ +# Delete __XLDIR__ Directory Scripts + +This directory contains scripts for deleting all directories ending with `__XLDIR__` in the specified path. + +## Script Description + +### 1. delete_xldir.sh (Full Version) + +A feature-rich version with multiple options and safety checks. + +**Usage:** +```bash +./scripts/delete_xldir.sh [options] +``` + +**Options:** +- `-f, --force` Force deletion without confirmation +- `-v, --verbose` Show verbose information +- `-d, --dry-run` Show directories to be deleted without actually deleting +- `-h, --help` Show help information + +**Examples:** +```bash +# Preview directories to be deleted (without actually deleting) +./scripts/delete_xldir.sh /path/to/search --dry-run + +# Interactive deletion (will ask for confirmation) +./scripts/delete_xldir.sh /path/to/search + +# Force deletion (without confirmation) +./scripts/delete_xldir.sh /path/to/search --force + +# Verbose mode deletion +./scripts/delete_xldir.sh /path/to/search --verbose +``` + +### 2. delete_xldir_simple.sh (Simple Version) + +A streamlined version that directly deletes found directories. + +**Usage:** +```bash +./scripts/delete_xldir_simple.sh +``` + +**Example:** +```bash +# Delete all directories ending with __XLDIR__ in the specified path +./scripts/delete_xldir_simple.sh /path/to/search +``` + +## How It Works + +Both scripts use the `find` command to locate directories: +```bash +find "$SEARCH_PATH" -type d -name "*__XLDIR__" +``` + +- `-type d`: Only search for directories +- `-name "*__XLDIR__"`: Find directories ending with `__XLDIR__` + +## Safety Notes + +⚠️ **Important Reminders:** +- Deletion operations are irreversible, please confirm the path is correct before use +- It's recommended to use the `--dry-run` option first to preview directories to be deleted +- For important data, please backup first + +## Use Cases + +These scripts are typically used for cleaning up temporary directories or metadata directories in storage systems, especially in distributed storage systems where `__XLDIR__` is commonly used as a specific directory identifier. \ No newline at end of file diff --git a/scripts/test/delete_xldir.sh b/scripts/test/delete_xldir.sh new file mode 100755 index 00000000..8b6896cd --- /dev/null +++ b/scripts/test/delete_xldir.sh @@ -0,0 +1,147 @@ +#!/bin/bash + +# Delete all directories ending with __XLDIR__ in the specified path + +# Check parameters +if [ $# -eq 0 ]; then + echo "Usage: $0 [options]" + echo "Options:" + echo " -f, --force Force deletion without confirmation" + echo " -v, --verbose Show verbose information" + echo " -d, --dry-run Show directories to be deleted without actually deleting" + echo "" + echo "Examples:" + echo " $0 /path/to/search" + echo " $0 /path/to/search --dry-run" + echo " $0 /path/to/search --force" + exit 1 +fi + +# Parse parameters +SEARCH_PATH="" +FORCE=false +VERBOSE=false +DRY_RUN=false + +while [[ $# -gt 0 ]]; do + case $1 in + -f|--force) + FORCE=true + shift + ;; + -v|--verbose) + VERBOSE=true + shift + ;; + -d|--dry-run) + DRY_RUN=true + shift + ;; + -h|--help) + echo "Usage: $0 [options]" + echo "Delete all directories ending with __XLDIR__ in the specified path" + exit 0 + ;; + -*) + echo "Unknown option: $1" + exit 1 + ;; + *) + if [ -z "$SEARCH_PATH" ]; then + SEARCH_PATH="$1" + else + echo "Error: Only one path can be specified" + exit 1 + fi + shift + ;; + esac +done + +# Check if path is provided +if [ -z "$SEARCH_PATH" ]; then + echo "Error: Search path must be specified" + exit 1 +fi + +# Check if path exists +if [ ! -d "$SEARCH_PATH" ]; then + echo "Error: Path '$SEARCH_PATH' does not exist or is not a directory" + exit 1 +fi + +# Find all directories ending with __XLDIR__ +echo "Searching in path: $SEARCH_PATH" +echo "Looking for directories ending with __XLDIR__..." + +# Use find command to locate directories +DIRS_TO_DELETE=$(find "$SEARCH_PATH" -type d -name "*__XLDIR__" 2>/dev/null) + +if [ -z "$DIRS_TO_DELETE" ]; then + echo "No directories ending with __XLDIR__ found" + exit 0 +fi + +# Display found directories +echo "Found the following directories:" +echo "$DIRS_TO_DELETE" +echo "" + +# Count directories +DIR_COUNT=$(echo "$DIRS_TO_DELETE" | wc -l) +echo "Total found: $DIR_COUNT directories" + +# If dry-run mode, only show without deleting +if [ "$DRY_RUN" = true ]; then + echo "" + echo "This is dry-run mode, no directories will be actually deleted" + echo "To actually delete these directories, remove the --dry-run option" + exit 0 +fi + +# If not force mode, ask for confirmation +if [ "$FORCE" = false ]; then + echo "" + read -p "Are you sure you want to delete these directories? (y/N): " -n 1 -r + echo "" + if [[ ! $REPLY =~ ^[Yy]$ ]]; then + echo "Operation cancelled" + exit 0 + fi +fi + +# Delete directories +echo "" +echo "Starting to delete directories..." + +deleted_count=0 +failed_count=0 + +while IFS= read -r dir; do + if [ -d "$dir" ]; then + if [ "$VERBOSE" = true ]; then + echo "Deleting: $dir" + fi + + if rm -rf "$dir" 2>/dev/null; then + ((deleted_count++)) + if [ "$VERBOSE" = true ]; then + echo " ✓ Deleted successfully" + fi + else + ((failed_count++)) + echo " ✗ Failed to delete: $dir" + fi + fi +done <<< "$DIRS_TO_DELETE" + +echo "" +echo "Deletion completed!" +echo "Successfully deleted: $deleted_count directories" +if [ $failed_count -gt 0 ]; then + echo "Failed to delete: $failed_count directories" + exit 1 +else + echo "All directories have been successfully deleted" + exit 0 +fi \ No newline at end of file diff --git a/scripts/test/delete_xldir_simple.sh b/scripts/test/delete_xldir_simple.sh new file mode 100755 index 00000000..04d4406e --- /dev/null +++ b/scripts/test/delete_xldir_simple.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +# Simple version: Delete all directories ending with __XLDIR__ in the specified path + +if [ $# -eq 0 ]; then + echo "Usage: $0 " + echo "Example: $0 /path/to/search" + exit 1 +fi + +SEARCH_PATH="$1" + +# Check if path exists +if [ ! -d "$SEARCH_PATH" ]; then + echo "Error: Path '$SEARCH_PATH' does not exist or is not a directory" + exit 1 +fi + +echo "Searching in path: $SEARCH_PATH" + +# Find and delete all directories ending with __XLDIR__ +find "$SEARCH_PATH" -type d -name "*__XLDIR__" -exec rm -rf {} \; 2>/dev/null + +echo "Deletion completed!" \ No newline at end of file