Skip to content

Commit

Permalink
fix: fix temp file don't remove when upload file. (#764)
Browse files Browse the repository at this point in the history
* build: improve cleanup after ms PR merged.

* fix: fix temp file don't remove when upload file.
  • Loading branch information
mo3et authored Oct 31, 2024
1 parent 37b6325 commit 6f8ab68
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
20 changes: 10 additions & 10 deletions .github/workflows/cleanup-after-milestone-prs-merged.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4.2.0

- name: Get the PR title and extract PR numbers
id: extract_pr_numbers
Expand All @@ -36,15 +36,6 @@ jobs:
echo "proceed=false" >> $GITHUB_OUTPUT
fi
- name: Delete branch after PR close
if: steps.extract_pr_numbers.outputs.proceed == 'true' || contains(github.event.pull_request.labels.*.name, 'milestone-merge')
run: |
BRANCH_NAME="${{ github.event.pull_request.head.ref }}"
echo "Branch to delete: $BRANCH_NAME"
git push origin --delete "$BRANCH_NAME"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Use extracted PR numbers and label PRs
if: (steps.extract_pr_numbers.outputs.proceed == 'true' || contains(github.event.pull_request.labels.*.name, 'milestone-merge')) && github.event.pull_request.merged == true
run: |
Expand All @@ -63,3 +54,12 @@ jobs:
done
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Delete branch after PR close
if: steps.extract_pr_numbers.outputs.proceed == 'true' || contains(github.event.pull_request.labels.*.name, 'milestone-merge')
run: |
BRANCH_NAME="${{ github.event.pull_request.head.ref }}"
echo "Branch to delete: $BRANCH_NAME"
git push origin --delete "$BRANCH_NAME"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
15 changes: 10 additions & 5 deletions internal/conversation_msg/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,12 +520,16 @@ func (c *Conversation) SendMessage(ctx context.Context, s *sdk_struct.MsgStruct,
break
}
name := s.FileElem.FileName

if name == "" {
name = s.FileElem.FilePath
}
if name == "" {
name = fmt.Sprintf("msg_file_%s.unknown", s.ClientMsgID)
}

delFile = append(delFile, s.FileElem.FilePath)

res, err := c.file.UploadFile(ctx, &file.UploadFileReq{
ContentType: content_type.GetType(s.FileElem.FileType, filepath.Ext(s.FileElem.FilePath), filepath.Ext(s.FileElem.FileName)),
Filepath: s.FileElem.FilePath,
Expand Down Expand Up @@ -657,7 +661,7 @@ func (c *Conversation) SendMessageNotOss(ctx context.Context, s *sdk_struct.MsgS
}

func (c *Conversation) sendMessageToServer(ctx context.Context, s *sdk_struct.MsgStruct, lc *model_struct.LocalConversation, callback open_im_sdk_callback.SendMsgCallBack,
delFile []string, offlinePushInfo *sdkws.OfflinePushInfo, options map[string]bool, isOnlineOnly bool) (*sdk_struct.MsgStruct, error) {
delFiles []string, offlinePushInfo *sdkws.OfflinePushInfo, options map[string]bool, isOnlineOnly bool) (*sdk_struct.MsgStruct, error) {
if isOnlineOnly {
utils.SetSwitchFromOptions(options, constant.IsHistory, false)
utils.SetSwitchFromOptions(options, constant.IsPersistent, false)
Expand Down Expand Up @@ -709,13 +713,14 @@ func (c *Conversation) sendMessageToServer(ctx context.Context, s *sdk_struct.Ms
s.ServerMsgID = sendMsgResp.ServerMsgID
go func() {
//remove media cache file
for _, v := range delFile {
err := os.Remove(v)
for _, file := range delFiles {
err := os.Remove(file)
if err != nil {
// log.Error("", "remove failed,", err.Error(), v)
log.ZError(ctx, "delete temp File is failed", err, "filePath", file)
}
// log.Debug("", "remove file: ", v)
// log.ZDebug(ctx, "remove temp file:", "file", file)
}

c.updateMsgStatusAndTriggerConversation(ctx, sendMsgResp.ClientMsgID, sendMsgResp.ServerMsgID, sendMsgResp.SendTime, constant.MsgStatusSendSuccess, s, lc, isOnlineOnly)
}()
return s, nil
Expand Down

0 comments on commit 6f8ab68

Please sign in to comment.