/ cmd / test-sync-debug / main.go
main.go
 1  package main
 2  
 3  import (
 4  	"context"
 5  	"fmt"
 6  	"log"
 7  	"os"
 8  
 9  	"keepSync/internal/providers"
10  )
11  
12  func main() {
13  	fmt.Println("šŸ” KeepSync Sync Debug Tool")
14  
15  	// Get S3 configuration from environment
16  	bucket := os.Getenv("S3_BUCKET")
17  	region := os.Getenv("S3_REGION")
18  	accessKey := os.Getenv("AWS_ACCESS_KEY_ID")
19  	secretKey := os.Getenv("AWS_SECRET_ACCESS_KEY")
20  
21  	if bucket == "" || accessKey == "" || secretKey == "" {
22  		fmt.Println("āŒ Missing S3 configuration. Please set:")
23  		fmt.Println("   S3_BUCKET, S3_REGION, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY")
24  		fmt.Println("")
25  		fmt.Println("Example:")
26  		fmt.Println("   export S3_BUCKET=storage-a01")
27  		fmt.Println("   export S3_REGION=us-east-1")
28  		fmt.Println("   export AWS_ACCESS_KEY_ID=your-access-key")
29  		fmt.Println("   export AWS_SECRET_ACCESS_KEY=your-secret-key")
30  		fmt.Println("")
31  		fmt.Println("Then run: keepsync sync /home/master/keepsync-files s3://storage-a01 --verbose")
32  		return
33  	}
34  
35  	fmt.Printf("āœ… S3 Configuration found:\n")
36  	fmt.Printf("   Bucket: %s\n", bucket)
37  	fmt.Printf("   Region: %s\n", region)
38  	fmt.Printf("   Access Key: %s...\n", accessKey[:min(len(accessKey), 8)])
39  
40  	// Test provider creation using the same logic as sync command
41  	basicConfig := map[string]interface{}{
42  		"bucket":     bucket,
43  		"region":     region,
44  		"access_key": accessKey,
45  		"secret_key": secretKey,
46  		"encrypt":    true,
47  		"compress":   true,
48  		"recursive":  true,
49  		"tpm_device": "/dev/tpmrm0",
50  		"key_name":   "s3-quantum-key",
51  	}
52  
53  	fmt.Println("\nšŸ”§ Testing provider creation...")
54  	provider, err := providers.CreateProviderFromType(context.Background(), "s3", basicConfig)
55  	if err != nil {
56  		log.Fatalf("āŒ Failed to create provider: %v", err)
57  	}
58  	defer provider.Close()
59  
60  	fmt.Println("āœ… Provider created successfully!")
61  
62  	// Test List functionality
63  	fmt.Println("\nšŸ“‹ Testing List functionality...")
64  	files, err := provider.List(context.Background(), "")
65  	if err != nil {
66  		log.Fatalf("āŒ List failed: %v", err)
67  	}
68  
69  	fmt.Printf("āœ… Found %d files on remote:\n", len(files))
70  	for i, file := range files {
71  		if i < 10 {
72  			fmt.Printf("   šŸ“„ %s\n", file)
73  		} else if i == 10 {
74  			fmt.Printf("   ... and %d more files\n", len(files)-10)
75  			break
76  		}
77  	}
78  
79  	fmt.Println("\nšŸŽ‰ Sync debug completed successfully!")
80  	fmt.Println("\nTo fix sync issues:")
81  	fmt.Println("1. Set the environment variables shown above")
82  	fmt.Println("2. Or create ~/.keepsync/config.json with provider configuration")
83  	fmt.Println("3. Run: keepsync sync /home/master/keepsync-files s3://storage-a01 --verbose")
84  }
85  
86  func min(a, b int) int {
87  	if a < b {
88  		return a
89  	}
90  	return b
91  }