7
7
"errors"
8
8
"fmt"
9
9
"io"
10
- "io/fs"
11
10
"net/http"
12
11
"os"
13
12
"path"
@@ -16,7 +15,6 @@ import (
16
15
"sync"
17
16
"time"
18
17
19
- "github.com/spf13/afero/mem"
20
18
"golang.org/x/sync/errgroup"
21
19
"golang.org/x/xerrors"
22
20
@@ -277,37 +275,25 @@ func (s *Artifactory) AddExtension(ctx context.Context, manifest *VSIXManifest,
277
275
return s .uri + dir , nil
278
276
}
279
277
280
- // Open returns a file from Artifactory.
281
- // TODO: Since we only extract a subset of files perhaps if the file does not
282
- // exist we should download the vsix and extract the requested file as a
283
- // fallback. Obviously this seems like quite a bit of overhead so we would
284
- // then emit a warning so we can notice that VS Code has added new asset types
285
- // that we should be extracting to avoid that overhead. Other solutions could
286
- // be implemented though like extracting the VSIX to disk locally and only
287
- // going to Artifactory for the VSIX when it is missing on disk (basically
288
- // using the disk as a cache).
289
- func (s * Artifactory ) Open (ctx context.Context , fp string ) (fs.File , error ) {
290
- resp , code , err := s .read (ctx , fp )
291
- if code != http .StatusOK || err != nil {
292
- switch code {
293
- case http .StatusNotFound :
294
- return nil , fs .ErrNotExist
295
- case http .StatusForbidden :
296
- return nil , fs .ErrPermission
297
- default :
298
- return nil , err
278
+ func (s * Artifactory ) FileServer () http.Handler {
279
+ // TODO: Since we only extract a subset of files perhaps if the file does not
280
+ // exist we should download the vsix and extract the requested file as a
281
+ // fallback. Obviously this seems like quite a bit of overhead so we would
282
+ // then emit a warning so we can notice that VS Code has added new asset types
283
+ // that we should be extracting to avoid that overhead. Other solutions could
284
+ // be implemented though like extracting the VSIX to disk locally and only
285
+ // going to Artifactory for the VSIX when it is missing on disk (basically
286
+ // using the disk as a cache).
287
+ return http .HandlerFunc (func (rw http.ResponseWriter , r * http.Request ) {
288
+ reader , code , err := s .read (r .Context (), r .URL .Path )
289
+ if err != nil {
290
+ http .Error (rw , err .Error (), code )
291
+ return
299
292
}
300
- }
301
-
302
- // TODO: Do no copy the bytes into memory, stream them rather than
303
- // storing the entire file into memory.
304
- f := mem .NewFileHandle (mem .CreateFile (fp ))
305
- _ , err = io .Copy (f , resp )
306
- if err != nil {
307
- return nil , err
308
- }
309
-
310
- return f , nil
293
+ defer reader .Close ()
294
+ rw .WriteHeader (http .StatusOK )
295
+ _ , _ = io .Copy (rw , reader )
296
+ })
311
297
}
312
298
313
299
func (s * Artifactory ) Manifest (ctx context.Context , publisher , name string , version Version ) (* VSIXManifest , error ) {
0 commit comments