@@ -20,8 +20,8 @@ import (
20
20
)
21
21
22
22
type sequinsOptions struct {
23
- LocalPath string
24
- CheckForSuccessFile bool
23
+ localPath string
24
+ checkForSuccessFile bool
25
25
}
26
26
27
27
type sequins struct {
@@ -96,7 +96,7 @@ func (s *sequins) refresh() error {
96
96
s .reloadLock .Lock ()
97
97
defer s .reloadLock .Unlock ()
98
98
99
- version , err := s .backend .LatestVersion (s .options .CheckForSuccessFile )
99
+ version , err := s .backend .LatestVersion (s .options .checkForSuccessFile )
100
100
if err != nil {
101
101
return err
102
102
}
@@ -109,14 +109,9 @@ func (s *sequins) refresh() error {
109
109
}
110
110
111
111
if version != currentVersion {
112
- path := filepath .Join (s .options .LocalPath , version )
112
+ path := filepath .Join (s .options .localPath , version )
113
113
114
- err := os .Mkdir (path , 0700 | os .ModeDir )
115
- if err != nil && ! os .IsExist (err ) {
116
- return err
117
- }
118
-
119
- if os .IsExist (err ) {
114
+ if _ , err := os .Stat (path ); err == nil {
120
115
log .Printf ("Version %s is already downloaded" , version )
121
116
} else {
122
117
log .Printf ("Downloading version %s from %s" , version , s .backend .DisplayPath (version ))
@@ -146,28 +141,26 @@ func (s *sequins) refresh() error {
146
141
return nil
147
142
}
148
143
149
- func (s * sequins ) download (version , destPath string ) (rterr error ) {
150
- // To avoid loading an incomplete download (#12), download into a temp dir
151
- // then rename the temp dir to destPath only if all downloads succeed.
152
- baseDir := path .Dir (destPath )
153
- workDir , err := ioutil .TempDir (baseDir , fmt .Sprintf ("version-%v" , version ))
144
+ func (s * sequins ) download (version , destPath string ) error {
145
+ workDir , err := ioutil .TempDir (path .Dir (destPath ), fmt .Sprintf ("version-%s-tmp-" , version ))
154
146
if err != nil {
155
147
return err
156
148
}
157
- defer func () {
158
- // Clean up the temp download dir in the event of a download error
159
- if err := os .RemoveAll (workDir ); err != nil && ! os .IsNotExist (err ) {
160
- rterr = err
161
- }
162
- }()
163
149
164
- if err := s .backend .Download (version , workDir ); err != nil {
150
+ // Clean up the temp download dir in the event of a download error
151
+ defer os .RemoveAll (workDir )
152
+
153
+ err = s .backend .Download (version , workDir )
154
+ if err != nil {
165
155
return err
166
156
}
167
157
168
- if err := os .Rename (workDir , destPath ); err != nil {
158
+ err = os .Rename (workDir , destPath )
159
+ if err != nil {
160
+ os .RemoveAll (destPath )
169
161
return err
170
162
}
163
+
171
164
return nil
172
165
}
173
166
0 commit comments