This commit is contained in:
parent
3e291bd062
commit
ec5ab68f22
|
|
@ -25,22 +25,31 @@ mc alias set $alias $endpoint $access_key $secret_key > /dev/null
|
||||||
mc mb --ignore-existing "$alias/$bucket" > /dev/null
|
mc mb --ignore-existing "$alias/$bucket" > /dev/null
|
||||||
|
|
||||||
filename=$(basename "$file")
|
filename=$(basename "$file")
|
||||||
|
filesize=$(stat -c %s "$file")
|
||||||
|
limit_bytes=1048576000 # 1000MB
|
||||||
|
|
||||||
|
# 判断读取长度
|
||||||
|
if [ "$filesize" -le "$limit_bytes" ]; then
|
||||||
|
read_size=$filesize
|
||||||
|
echo "📦 文件小于等于 1GB,使用全文件做 hash 校验"
|
||||||
|
local_hash=$(sha256sum "$file" | awk '{print $1}')
|
||||||
|
else
|
||||||
|
read_size=$limit_bytes
|
||||||
|
echo "📦 文件大于 1GB,仅使用前 1000MB 做 hash 校验"
|
||||||
|
local_hash=$(head -c "$read_size" "$file" | sha256sum | awk '{print $1}')
|
||||||
|
fi
|
||||||
|
|
||||||
echo "🚀 开始上传文件: $file"
|
echo "🚀 开始上传文件: $file"
|
||||||
mc cp "$file" "$alias/$bucket/$filename"
|
mc cp "$file" "$alias/$bucket/$filename"
|
||||||
|
|
||||||
echo "✅ 上传完成,开始验证..."
|
echo "✅ 上传完成,开始验证远程数据..."
|
||||||
|
|
||||||
# 计算上传前本地文件前 1MB 的 SHA256
|
remote_hash=$(curl -s -H "Range: bytes=0-$((read_size - 1))" "$host/$bucket/$filename" | sha256sum | awk '{print $1}')
|
||||||
local_hash=$(head -c 1048576 "$file" | sha256sum | awk '{print $1}')
|
|
||||||
|
|
||||||
# 下载远程同名文件的前 1MB 来比较(使用 Range)
|
|
||||||
remote_hash=$(curl -s -H "Range: bytes=0-1048575" "$host/$bucket/$filename" | sha256sum | awk '{print $1}')
|
|
||||||
|
|
||||||
if [ "$local_hash" != "$remote_hash" ]; then
|
if [ "$local_hash" != "$remote_hash" ]; then
|
||||||
echo "❌ 验证失败:远程文件仍然是旧的,未被覆盖!"
|
echo "❌ 验证失败:远程文件未被覆盖或延迟更新"
|
||||||
echo "本地: $local_hash"
|
echo "本地 hash: $local_hash"
|
||||||
echo "远程: $remote_hash"
|
echo "远程 hash: $remote_hash"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue