@@ -28,55 +28,14 @@ func createZipFile(sourceDir, zipPath string) error {
28
28
zipWriter := zip .NewWriter (zipFile )
29
29
defer zipWriter .Close ()
30
30
31
- return filepath .Walk (sourceDir , func (filePath string , info os.FileInfo , err error ) error {
32
- if err != nil {
33
- return fmt .Errorf ("error walking path %s: %v" , filePath , err )
34
- }
35
-
36
- // Skip the root directory itself
37
- if filePath == sourceDir {
38
- return nil
39
- }
40
-
41
- // Get the relative path from the source directory
42
- relPath , err := filepath .Rel (sourceDir , filePath )
43
- if err != nil {
44
- return fmt .Errorf ("failed to get relative path for %s: %v" , filePath , err )
45
- }
46
-
47
- // Convert Windows backslashes to forward slashes
48
- zipEntryPath := strings .ReplaceAll (relPath , "\\ " , "/" )
49
-
50
- // Create directory entries for directories
51
- if info .IsDir () {
52
- zipEntryPath += "/"
53
- _ , err := zipWriter .Create (zipEntryPath )
54
- if err != nil {
55
- return fmt .Errorf ("failed to create directory entry %s: %v" , zipEntryPath , err )
56
- }
57
- return nil
58
- }
59
-
60
- // Create file entry
61
- fileWriter , err := zipWriter .Create (zipEntryPath )
62
- if err != nil {
63
- return fmt .Errorf ("failed to create file entry %s: %v" , zipEntryPath , err )
64
- }
65
-
66
- // Copy file content
67
- file , err := os .Open (filePath )
68
- if err != nil {
69
- return fmt .Errorf ("failed to open file %s: %v" , filePath , err )
70
- }
71
- defer file .Close ()
72
-
73
- _ , err = io .Copy (fileWriter , file )
74
- if err != nil {
75
- return fmt .Errorf ("failed to copy file content for %s: %v" , filePath , err )
76
- }
31
+ // Use AddFS to add the entire directory
32
+ fsys := os .DirFS (sourceDir )
33
+ err = zipWriter .AddFS (fsys )
34
+ if err != nil {
35
+ return fmt .Errorf ("failed to add directory to ZIP: %v" , err )
36
+ }
77
37
78
- return nil
79
- })
38
+ return nil
80
39
}
81
40
82
41
func (a * Acquisition ) StoreSecurely () error {
0 commit comments