Skip to content

Fix package upload temp path #34196

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions modules/setting/packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ import (
// Package registry settings
var (
Packages = struct {
Storage *Storage
Enabled bool
ChunkedUploadPath string
Storage *Storage
Enabled bool

LimitTotalOwnerCount int64
LimitTotalOwnerSize int64
Expand Down Expand Up @@ -65,13 +64,6 @@ func loadPackagesFrom(rootCfg ConfigProvider) (err error) {
return err
}

if HasInstallLock(rootCfg) {
Packages.ChunkedUploadPath, err = AppDataTempDir("package-upload").MkdirAllSub("")
if err != nil {
return fmt.Errorf("unable to create chunked upload directory: %w", err)
}
}

Packages.LimitTotalOwnerSize = mustBytes(sec, "LIMIT_TOTAL_OWNER_SIZE")
Packages.LimitSizeAlpine = mustBytes(sec, "LIMIT_SIZE_ALPINE")
Packages.LimitSizeArch = mustBytes(sec, "LIMIT_SIZE_ARCH")
Expand Down
21 changes: 15 additions & 6 deletions services/packages/container/blob_uploader.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
packages_model "code.gitea.io/gitea/models/packages"
packages_module "code.gitea.io/gitea/modules/packages"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/modules/tempdir"
)

var (
Expand All @@ -30,8 +30,12 @@ type BlobUploader struct {
reading bool
}

func buildFilePath(id string) string {
return util.FilePathJoinAbs(setting.Packages.ChunkedUploadPath, id)
func uploadPathTempDir() *tempdir.TempDir {
return setting.AppDataTempDir("package-upload")
}

func buildFilePath(uploadPath *tempdir.TempDir, id string) string {
return uploadPath.JoinPath(id)
}

// NewBlobUploader creates a new blob uploader for the given id
Expand All @@ -48,7 +52,12 @@ func NewBlobUploader(ctx context.Context, id string) (*BlobUploader, error) {
}
}

f, err := os.OpenFile(buildFilePath(model.ID), os.O_RDWR|os.O_CREATE, 0o666)
uploadPath := uploadPathTempDir()
_, err = uploadPath.MkdirAllSub("")
if err != nil {
return nil, err
}
f, err := os.OpenFile(buildFilePath(uploadPath, model.ID), os.O_RDWR|os.O_CREATE, 0o666)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -118,13 +127,13 @@ func (u *BlobUploader) Read(p []byte) (int, error) {
return u.file.Read(p)
}

// Remove deletes the data and the model of a blob upload
// RemoveBlobUploadByID Remove deletes the data and the model of a blob upload
func RemoveBlobUploadByID(ctx context.Context, id string) error {
if err := packages_model.DeleteBlobUploadByID(ctx, id); err != nil {
return err
}

err := os.Remove(buildFilePath(id))
err := os.Remove(buildFilePath(uploadPathTempDir(), id))
if err != nil && !os.IsNotExist(err) {
return err
}
Expand Down