Changeset 0.21.2 (#88)
This commit is contained in:
@@ -33,14 +33,30 @@ const (
|
||||
// Returns the number of files extracted. Respects workspace quota.
|
||||
// format must be "zip" or "tar.gz".
|
||||
func (fs *FS) ExtractArchive(ctx context.Context, w *models.Workspace, archivePath, format string) (int, error) {
|
||||
var count int
|
||||
var err error
|
||||
switch format {
|
||||
case "zip":
|
||||
return fs.extractZip(ctx, w, archivePath)
|
||||
count, err = fs.extractZip(ctx, w, archivePath)
|
||||
case "tar.gz", "tgz":
|
||||
return fs.extractTarGz(ctx, w, archivePath)
|
||||
count, err = fs.extractTarGz(ctx, w, archivePath)
|
||||
default:
|
||||
return 0, fmt.Errorf("workspace: unsupported archive format: %s", format)
|
||||
}
|
||||
|
||||
// Trigger batch indexing for all extracted files (v0.21.2)
|
||||
if err == nil && fs.indexer != nil && count > 0 {
|
||||
files, listErr := fs.store.ListFiles(ctx, w.ID, "", true)
|
||||
if listErr == nil {
|
||||
var teamID *string
|
||||
if w.OwnerType == models.WorkspaceOwnerTeam {
|
||||
teamID = &w.OwnerID
|
||||
}
|
||||
fs.indexer.IndexBatch(w, files, w.OwnerID, teamID)
|
||||
}
|
||||
}
|
||||
|
||||
return count, err
|
||||
}
|
||||
|
||||
func (fs *FS) extractZip(ctx context.Context, w *models.Workspace, archivePath string) (int, error) {
|
||||
|
||||
Reference in New Issue
Block a user