From d083ecd88e31c1143bf24a02d377ff7d14c7c78f Mon Sep 17 00:00:00 2001 From: suhailroushan Date: Sun, 16 Mar 2025 15:23:03 +0000 Subject: [PATCH 1/3] Optimize license header script and improve efficiency --- add_license_notice.sh | 65 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 57 insertions(+), 8 deletions(-) diff --git a/add_license_notice.sh b/add_license_notice.sh index eac98e986..c2a7a94fb 100755 --- a/add_license_notice.sh +++ b/add_license_notice.sh @@ -3,16 +3,65 @@ LICENSE_NOTICE="// Copyright (c) 2022-present, DiceDB contributors // All rights reserved. Licensed under the BSD 3-Clause License. See LICENSE file in the project root for full license information." -# Find all Go files and add the notice if not already present -find . -type f -name "*.go" | while read -r FILE; do - # Check if the file already contains the license notice - if ! grep -qF "$LICENSE_NOTICE" "$FILE"; then - # Add the license notice at the top of the file - { echo "$LICENSE_NOTICE"; echo ""; cat "$FILE"; } > temp_file && mv temp_file "$FILE" - echo "Added license notice to $FILE" +# Function to add license notice while preserving shebang and package declaration +add_license_notice() { + local file="$1" + local temp_file + local permissions + + # Preserve file permissions + permissions=$(stat -c "%a" "$file") + + # Create a temporary file + temp_file=$(mktemp) + + # Read the first two lines to check for shebang and package declaration + read -r first_line < "$file" + read -r second_line < <(sed -n '2p' "$file") + + if [[ "$first_line" =~ ^#! ]]; then + # If the first line is a shebang, preserve it + { + echo "$first_line" + echo "" + echo "$LICENSE_NOTICE" + echo "" + tail -n +2 "$file" + } > "$temp_file" + elif [[ "$first_line" =~ ^package ]]; then + # If the first line is a package declaration, insert the license above it + { + echo "$LICENSE_NOTICE" + echo "" + cat "$file" + } > "$temp_file" else - echo "License notice already present in $FILE" + # Just prepend the license notice + { + echo "$LICENSE_NOTICE" + echo "" + cat "$file" + } > "$temp_file" fi + + # Replace original file with modified one + mv "$temp_file" "$file" + + # Restore file permissions + chmod "$permissions" "$file" + + echo "Added license notice to $file" +} + +export -f add_license_notice +export LICENSE_NOTICE + +# Find all Go files that don't already contain the license +mapfile -t files < <(find . -type f -name "*.go" ! -path "./vendor/*" ! -exec grep -qF "$LICENSE_NOTICE" {} \; -print) + +# Process files +for file in "${files[@]}"; do + add_license_notice "$file" done echo "Finished adding license notice to all Go files." From 038f8f9185c750b20379efba07db4a4d3a472f2b Mon Sep 17 00:00:00 2001 From: suhailroushan Date: Sun, 16 Mar 2025 15:31:23 +0000 Subject: [PATCH 2/3] exit on WAL initialization failure to prevent data corruption --- server/main.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/server/main.go b/server/main.go index 34bfc72be..22c8a7bcf 100644 --- a/server/main.go +++ b/server/main.go @@ -97,10 +97,10 @@ func Start() { wl = _wl if err := wl.Init(time.Now()); err != nil { - slog.Error("could not initialize WAL", slog.Any("error", err)) - } else { - go wal.InitBG(wl) + slog.Fatal("WAL initialization failed, shutting down", slog.Any("error", err)) } + go wal.InitBG(wl) + slog.Debug("WAL initialization complete") } From 5f44afa5b747c9f6a6282bdcf6d9b80a7e844519 Mon Sep 17 00:00:00 2001 From: Suhail Roushan Date: Mon, 24 Mar 2025 02:20:06 +0530 Subject: [PATCH 3/3] Delete add_license_notice.sh --- add_license_notice.sh | 67 ------------------------------------------- 1 file changed, 67 deletions(-) delete mode 100755 add_license_notice.sh diff --git a/add_license_notice.sh b/add_license_notice.sh deleted file mode 100755 index c2a7a94fb..000000000 --- a/add_license_notice.sh +++ /dev/null @@ -1,67 +0,0 @@ -#!/bin/bash - -LICENSE_NOTICE="// Copyright (c) 2022-present, DiceDB contributors -// All rights reserved. Licensed under the BSD 3-Clause License. See LICENSE file in the project root for full license information." - -# Function to add license notice while preserving shebang and package declaration -add_license_notice() { - local file="$1" - local temp_file - local permissions - - # Preserve file permissions - permissions=$(stat -c "%a" "$file") - - # Create a temporary file - temp_file=$(mktemp) - - # Read the first two lines to check for shebang and package declaration - read -r first_line < "$file" - read -r second_line < <(sed -n '2p' "$file") - - if [[ "$first_line" =~ ^#! ]]; then - # If the first line is a shebang, preserve it - { - echo "$first_line" - echo "" - echo "$LICENSE_NOTICE" - echo "" - tail -n +2 "$file" - } > "$temp_file" - elif [[ "$first_line" =~ ^package ]]; then - # If the first line is a package declaration, insert the license above it - { - echo "$LICENSE_NOTICE" - echo "" - cat "$file" - } > "$temp_file" - else - # Just prepend the license notice - { - echo "$LICENSE_NOTICE" - echo "" - cat "$file" - } > "$temp_file" - fi - - # Replace original file with modified one - mv "$temp_file" "$file" - - # Restore file permissions - chmod "$permissions" "$file" - - echo "Added license notice to $file" -} - -export -f add_license_notice -export LICENSE_NOTICE - -# Find all Go files that don't already contain the license -mapfile -t files < <(find . -type f -name "*.go" ! -path "./vendor/*" ! -exec grep -qF "$LICENSE_NOTICE" {} \; -print) - -# Process files -for file in "${files[@]}"; do - add_license_notice "$file" -done - -echo "Finished adding license notice to all Go files."