Merge pull request #1186 from jmorganca/mxyng/copy-blob

fix cross device rename
This commit is contained in:
Michael Yang 2023-11-17 21:54:53 -08:00 committed by GitHub
commit 42e43736a4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -666,8 +666,14 @@ func HeadBlobHandler(c *gin.Context) {
}
func CreateBlobHandler(c *gin.Context) {
targetPath, err := GetBlobsPath(c.Param("digest"))
if err != nil {
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
hash := sha256.New()
temp, err := os.CreateTemp("", c.Param("digest"))
temp, err := os.CreateTemp(filepath.Dir(targetPath), c.Param("digest"))
if err != nil {
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
@ -690,12 +696,6 @@ func CreateBlobHandler(c *gin.Context) {
return
}
targetPath, err := GetBlobsPath(c.Param("digest"))
if err != nil {
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
if err := os.Rename(temp.Name(), targetPath); err != nil {
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return