/ test-sync-behavior-fix.sh
test-sync-behavior-fix.sh
 1  #!/bin/bash
 2  
 3  echo "🔄 SYNC BEHAVIOR FIX DEMONSTRATION"
 4  echo "=================================="
 5  
 6  # Step 1: Stop the service to test manual sync
 7  echo "🛑 Stopping KeepSync service..."
 8  sudo systemctl stop keepsync
 9  
10  # Step 2: Clear local directory and create test files
11  echo "📁 Setting up test scenario..."
12  rm -f /home/master/keepsync-files/*
13  
14  echo "Creating initial test files..."
15  echo "File 1 content" > /home/master/keepsync-files/file1.txt
16  echo "File 2 content" > /home/master/keepsync-files/file2.txt
17  echo "File 3 content" > /home/master/keepsync-files/file3.txt
18  
19  echo "✅ Local files created:"
20  ls -la /home/master/keepsync-files/
21  
22  # Step 3: Upload files to remote
23  echo "📤 Uploading files to remote..."
24  go run cmd/test-quantum-upload/main.go
25  
26  # Step 4: Verify files are on remote
27  echo "🔍 Checking remote files..."
28  go run cmd/test-s3-raw-list/main.go | head -5
29  
30  # Step 5: Delete a file locally to test deletion behavior
31  echo "🗑️ Deleting file2.txt locally to test sync behavior..."
32  rm /home/master/keepsync-files/file2.txt
33  
34  echo "Local files after deletion:"
35  ls -la /home/master/keepsync-files/
36  
37  # Step 6: Test sync with delete enabled
38  echo "🔄 Testing sync with --delete flag (should delete file2.txt remotely)..."
39  echo "This should DELETE file2.txt from remote storage, not re-download it"
40  
41  # Use the CLI sync command with delete flag
42  ./keepsync sync /home/master/keepsync-files s3://keepsync-files --delete --verbose
43  
44  # Step 7: Verify the file was deleted remotely
45  echo "🔍 Checking remote files after sync with delete..."
46  echo "file2.txt should be GONE from remote storage:"
47  go run cmd/test-s3-raw-list/main.go | head -5
48  
49  # Step 8: Test initial sync scenario (empty local, populated remote)
50  echo "📥 Testing initial sync: empty local directory should download from remote..."
51  mkdir -p /tmp/test-empty-local
52  ./keepsync sync /tmp/test-empty-local s3://keepsync-files --bidirectional --verbose
53  
54  echo "Files downloaded to empty directory:"
55  ls -la /tmp/test-empty-local/
56  
57  echo "🎉 SYNC BEHAVIOR FIX VERIFICATION COMPLETE!"
58  echo "=========================================="
59  echo "✅ Files deleted locally are now deleted remotely (not re-downloaded)"
60  echo "✅ Empty local directory downloads from remote"
61  echo "✅ Smart initial sync logic working"
62  echo "✅ Bidirectional sync respects delete priority"