🐛 Fix schedule deletion will delete referenced file
This commit is contained in:
		
							
								
								
									
										8
									
								
								.idea/workspace.xml
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										8
									
								
								.idea/workspace.xml
									
									
									
										generated
									
									
									
								
							@@ -4,10 +4,9 @@
 | 
				
			|||||||
    <option name="autoReloadType" value="ALL" />
 | 
					    <option name="autoReloadType" value="ALL" />
 | 
				
			||||||
  </component>
 | 
					  </component>
 | 
				
			||||||
  <component name="ChangeListManager">
 | 
					  <component name="ChangeListManager">
 | 
				
			||||||
    <list default="true" id="18dd0d68-b4b8-40db-9734-9119b5c848bd" name="更改" comment=":recycle: Split mark and delete file">
 | 
					    <list default="true" id="18dd0d68-b4b8-40db-9734-9119b5c848bd" name="更改" comment=":bug: Fix migration issue on pools">
 | 
				
			||||||
      <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
 | 
					      <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
 | 
				
			||||||
      <change beforePath="$PROJECT_DIR$/pkg/internal/database/migrator.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/database/migrator.go" afterDir="false" />
 | 
					      <change beforePath="$PROJECT_DIR$/pkg/internal/services/recycler.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/services/recycler.go" afterDir="false" />
 | 
				
			||||||
      <change beforePath="$PROJECT_DIR$/pkg/internal/models/pools.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/models/pools.go" afterDir="false" />
 | 
					 | 
				
			||||||
    </list>
 | 
					    </list>
 | 
				
			||||||
    <option name="SHOW_DIALOG" value="false" />
 | 
					    <option name="SHOW_DIALOG" value="false" />
 | 
				
			||||||
    <option name="HIGHLIGHT_CONFLICTS" value="true" />
 | 
					    <option name="HIGHLIGHT_CONFLICTS" value="true" />
 | 
				
			||||||
@@ -124,7 +123,8 @@
 | 
				
			|||||||
    <MESSAGE value=":sparkles: Attachment has pool" />
 | 
					    <MESSAGE value=":sparkles: Attachment has pool" />
 | 
				
			||||||
    <MESSAGE value=":sparkles: Pool clean by lifecycle config" />
 | 
					    <MESSAGE value=":sparkles: Pool clean by lifecycle config" />
 | 
				
			||||||
    <MESSAGE value=":recycle: Split mark and delete file" />
 | 
					    <MESSAGE value=":recycle: Split mark and delete file" />
 | 
				
			||||||
    <option name="LAST_COMMIT_MESSAGE" value=":recycle: Split mark and delete file" />
 | 
					    <MESSAGE value=":bug: Fix migration issue on pools" />
 | 
				
			||||||
 | 
					    <option name="LAST_COMMIT_MESSAGE" value=":bug: Fix migration issue on pools" />
 | 
				
			||||||
  </component>
 | 
					  </component>
 | 
				
			||||||
  <component name="VgoProject">
 | 
					  <component name="VgoProject">
 | 
				
			||||||
    <settings-migrated>true</settings-migrated>
 | 
					    <settings-migrated>true</settings-migrated>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -51,7 +51,7 @@ func RunMarkDeletionTask() {
 | 
				
			|||||||
	for _, pool := range pendingPools {
 | 
						for _, pool := range pendingPools {
 | 
				
			||||||
		lifecycle := fmt.Sprintf("%d seconds", *pool.Config.Data().ExistLifecycle)
 | 
							lifecycle := fmt.Sprintf("%d seconds", *pool.Config.Data().ExistLifecycle)
 | 
				
			||||||
		tx := database.C.
 | 
							tx := database.C.
 | 
				
			||||||
			Where("pool_id = ? AND created_at < NOW() - INTERVAL ?", pool.ID, lifecycle).
 | 
								Where("pool_id = ? AND  AND created_at < NOW() - INTERVAL ?", pool.ID, lifecycle).
 | 
				
			||||||
			Updates(&models.Attachment{CleanedAt: lo.ToPtr(time.Now())})
 | 
								Updates(&models.Attachment{CleanedAt: lo.ToPtr(time.Now())})
 | 
				
			||||||
		log.Info().
 | 
							log.Info().
 | 
				
			||||||
			Str("pool", pool.Alias).
 | 
								Str("pool", pool.Alias).
 | 
				
			||||||
@@ -68,6 +68,9 @@ func RunScheduleDeletionTask() {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for idx, attachment := range attachments {
 | 
						for idx, attachment := range attachments {
 | 
				
			||||||
 | 
							if attachment.RefID != nil {
 | 
				
			||||||
 | 
								continue
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
		if err := DeleteFile(attachment); err != nil {
 | 
							if err := DeleteFile(attachment); err != nil {
 | 
				
			||||||
			log.Error().
 | 
								log.Error().
 | 
				
			||||||
				Uint("id", attachment.ID).
 | 
									Uint("id", attachment.ID).
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user