DanielAuerX commented on PR #1335:
URL: https://github.com/apache/answer/pull/1335#issuecomment-2887707003

   > @DanielAuerX
   > 
   > For issue 2, here are my reproduction steps.
   > 
   > 1. Upload an avatar and save the profile.
   > 2. Check the avatar dir. (The file exists)
   > 3. Switch the avatar to system and save the profile.
   > 4. Check the avatar dir. (The file not exists)
   > 
   > ```
   > 1. ➜  avatar git:(fix_file_record) ls
   > 2. ➜  avatar git:(fix_file_record) ls
   > 5sVCXwyhsbm.png
   > 4. ➜  avatar git:(fix_file_record) ls
   > ➜  avatar git:(fix_file_record) 
   > ```
   > 
   > This is the reason for the problem.
   > 
   > ```go
   > if oldAvatar.Type == "custom" && (newAvatar.Type != "custom" || 
oldAvatar.Custom != newAvatar.Custom) {
   > ```
   > 
   > At this time, `newAvatar.Type != "custom"` so the file will be deleted.
   > 
   > To make the logic simple, perhaps it could be implemented like this.
   > 
   > ```go
   >    // As long as there are no original files, there must be no need to 
delete
   >    if len(oldAvatar.Custom) == 0 {
   >            return
   >    }
   >    // At this point, it turns out that the old file must exist. 
   >    // Then delete as long as the new file and the old file are 
inconsistent as you say. 
   >    // Whatever type the user chooses.
   >    if oldAvatar.Custom != newAvatar.Custom {
   >            fileRecord, err := us.fileRecordService.GetFileRecordByURL(ctx, 
oldAvatar.Custom)
   >    }
   > ```
   
   Should be done now


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@answer.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to