@@ -21,7 +21,6 @@ import (
21
21
func (sl * Safelock ) Encrypt (ctx context.Context , inputPaths []string , output io.Writer , password string ) (err error ) {
22
22
errs := make (chan error )
23
23
signals , closeSignals := sl .getExitSignals ()
24
- start := 20.0
25
24
26
25
if ctx == nil {
27
26
ctx = context .Background ()
@@ -36,25 +35,18 @@ func (sl *Safelock) Encrypt(ctx context.Context, inputPaths []string, output io.
36
35
Trigger (StatusEnd .Str ())
37
36
38
37
go func () {
39
- var inputFiles []archiver.File
40
-
41
38
if err = sl .validateEncryptionInputs (inputPaths , password ); err != nil {
42
39
errs <- fmt .Errorf ("invalid encryption input > %w" , err )
43
40
return
44
41
}
45
42
46
- if inputFiles , err = sl .getInputFiles (ctx , inputPaths , 5.0 , start ); err != nil {
47
- errs <- fmt .Errorf ("failed to read and list input paths > %w" , err )
48
- return
49
- }
50
-
51
43
ctx , cancel := context .WithCancel (ctx )
52
- calc := utils .NewPathsCalculator (start , inputFiles )
44
+ calc := utils .NewPathsCalculator (20.0 )
53
45
rw := newWriter (password , output , cancel , calc , sl .EncryptionConfig , errs )
54
46
rw .asyncGcm = newAsyncGcm (password , sl .EncryptionConfig , errs )
55
47
56
- if err = sl .encryptFiles (ctx , inputFiles , rw , calc ); err != nil {
57
- errs <- fmt . Errorf ( "failed to create encrypted archive file > %w" , err )
48
+ if err = sl .encryptFiles (ctx , inputPaths , rw , calc ); err != nil {
49
+ errs <- err
58
50
return
59
51
}
60
52
@@ -109,51 +101,36 @@ func (sl *Safelock) validateEncryptionInputs(inputPaths []string, pwd string) (e
109
101
return
110
102
}
111
103
112
- func (sl * Safelock ) getInputFiles (
104
+ func (sl * Safelock ) encryptFiles (
113
105
ctx context.Context ,
114
- paths []string ,
115
- start , end float64 ,
116
- ) (files []archiver.File , err error ) {
117
- sl .updateStatus ("Listing and preparing files " , start )
118
-
119
- filesMap := make (map [string ]string , len (paths ))
120
- ctx , cancel := context .WithCancel (ctx )
121
- defer cancel ()
106
+ inputPaths []string ,
107
+ slWriter * safelockWriter ,
108
+ calc * utils.PercentCalculator ,
109
+ ) (err error ) {
110
+ sl .updateStatus ("Listing and preparing files " , 5.0 )
122
111
123
- go func () {
124
- for {
125
- select {
126
- case <- ctx .Done ():
127
- return
128
- default :
129
- if end >= start {
130
- start += 1.0
131
- time .Sleep (time .Second / 5 )
132
- }
133
- }
134
- }
135
- }()
112
+ var files []archiver.File
113
+ var filesMap = make (map [string ]string , len (inputPaths ))
136
114
137
- for _ , path := range paths {
115
+ for _ , path := range inputPaths {
138
116
filesMap [path ] = ""
139
117
}
140
118
141
119
if files , err = archiver .FilesFromDisk (nil , filesMap ); err != nil {
120
+ err = fmt .Errorf ("failed to read and list input paths > %w" , err )
142
121
return
143
122
}
144
123
145
- return
146
- }
124
+ go func () {
125
+ for _ , file := range files {
126
+ calc .InputSize += int (file .Size ())
127
+ }
147
128
148
- func (sl * Safelock ) encryptFiles (
149
- ctx context.Context ,
150
- inputFiles []archiver.File ,
151
- slWriter * safelockWriter ,
152
- calc * utils.PercentCalculator ,
153
- ) (err error ) {
154
- go sl .updateProgressStatus (ctx , "Encrypting" , calc )
129
+ sl .updateProgressStatus (ctx , "Encrypting" , calc )
130
+ }()
155
131
156
- if err = sl .archive (ctx , slWriter , inputFiles ); err != nil {
132
+ if err = sl .archive (ctx , slWriter , files ); err != nil {
133
+ err = fmt .Errorf ("failed to create encrypted archive file > %w" , err )
157
134
return
158
135
}
159
136
0 commit comments