Skip to content

Commit 74ca4f9

Browse files
committed
Delegate vsix manifest addition to storage impl
This will let them store extensions however they want rather than assuming a specific structure.
1 parent 05b408f commit 74ca4f9

File tree

2 files changed

+29
-17
lines changed

2 files changed

+29
-17
lines changed

storage/local.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ func (s *Local) AddExtension(ctx context.Context, vsix []byte) (*Extension, erro
6666
}
6767

6868
// Copy the VSIX itself as well.
69-
name := fmt.Sprintf("%s.%s-%s", identity.Publisher, identity.ID, identity.Version)
70-
vsixName := fmt.Sprintf("%s.vsix", name)
69+
id := extensionID(manifest)
70+
vsixName := fmt.Sprintf("%s.vsix", id)
7171
dst, err := os.OpenFile(filepath.Join(dir, vsixName), os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o644)
7272
if err != nil {
7373
return nil, err
@@ -78,7 +78,7 @@ func (s *Local) AddExtension(ctx context.Context, vsix []byte) (*Extension, erro
7878
return nil, err
7979
}
8080

81-
ext := &Extension{ID: name, Location: dir}
81+
ext := &Extension{ID: id, Location: dir}
8282
for _, prop := range manifest.Metadata.Properties.Property {
8383
if prop.Value == "" {
8484
continue
@@ -163,7 +163,21 @@ func (s *Local) Manifest(ctx context.Context, publisher, extension, version stri
163163
}
164164
defer reader.Close()
165165

166-
return parseVSIXManifest(reader)
166+
manifest, err := parseVSIXManifest(reader)
167+
if err != nil {
168+
return nil, err
169+
}
170+
171+
// The extension asset is not stored in the manifest. Since we always store
172+
// it next to the manifest using the publisher.name-version format we can set
173+
// that as the path.
174+
manifest.Assets.Asset = append(manifest.Assets.Asset, VSIXAsset{
175+
Type: VSIXAssetType,
176+
Path: fmt.Sprintf("%s.vsix", extensionID(manifest)),
177+
Addressable: "true",
178+
})
179+
180+
return manifest, nil
167181
}
168182

169183
func (s *Local) WalkExtensions(ctx context.Context, fn func(manifest *VSIXManifest, versions []string) error) error {

storage/storage.go

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,9 @@ type Storage interface {
109109
// FileServer provides a handler for fetching extension repository files from
110110
// a client.
111111
FileServer() http.Handler
112-
// Manifest returns the manifest for the provided extension version.
112+
// Manifest returns the manifest for the provided extension version. The
113+
// extension asset (the VSIX) will always be added even if it does not exist
114+
// in the manifest on disk.
113115
Manifest(ctx context.Context, publisher, extension, version string) (*VSIXManifest, error)
114116
// WalkExtensions applies a function over every extension providing the
115117
// manifest for the latest version and a list of all available versions. If
@@ -128,18 +130,6 @@ func parseVSIXManifest(reader io.Reader) (*VSIXManifest, error) {
128130
return nil, err
129131
}
130132

131-
// The extension asset is not stored in the manifest. Since we always store
132-
// it next to the manifest using the publisher.name-version format we can set
133-
// that as the path.
134-
vm.Assets.Asset = append(vm.Assets.Asset, VSIXAsset{
135-
Type: VSIXAssetType,
136-
Path: fmt.Sprintf("%s.%s-%s.vsix",
137-
vm.Metadata.Identity.Publisher,
138-
vm.Metadata.Identity.ID,
139-
vm.Metadata.Identity.Version),
140-
Addressable: "true",
141-
})
142-
143133
return vm, nil
144134
}
145135

@@ -183,3 +173,11 @@ func ReadVSIX(ctx context.Context, source string) ([]byte, error) {
183173
N: 100 * 1000 * 1000, // 100 MB
184174
})
185175
}
176+
177+
// extensionID returns the full ID of an extension.
178+
func extensionID(manifest *VSIXManifest) string {
179+
return fmt.Sprintf("%s.%s-%s",
180+
manifest.Metadata.Identity.Publisher,
181+
manifest.Metadata.Identity.ID,
182+
manifest.Metadata.Identity.Version)
183+
}

0 commit comments

Comments
 (0)