From 6d6db76c80fb31a6e333b4f9d178cb8b0192d477 Mon Sep 17 00:00:00 2001 From: KongQun Yang Date: Fri, 14 Dec 2018 17:02:13 -0800 Subject: [PATCH] Retry file deletion if it fails The file deletion could fail if it is still held by the web server. This CL adds retry logic to retry the deletion. Closes #533. Change-Id: Ib42ed8db11f32897a29e3b58c1be89d05f5dd034 --- packager/hls/base/media_playlist.cc | 6 +++++- packager/mpd/base/representation.cc | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/packager/hls/base/media_playlist.cc b/packager/hls/base/media_playlist.cc index 15b9375542..cb26655034 100644 --- a/packager/hls/base/media_playlist.cc +++ b/packager/hls/base/media_playlist.cc @@ -636,7 +636,11 @@ void MediaPlaylist::RemoveOldSegment(int64_t start_time) { while (segments_to_be_removed_.size() > hls_params_.preserved_segments_outside_live_window) { VLOG(2) << "Deleting " << segments_to_be_removed_.front(); - File::Delete(segments_to_be_removed_.front().c_str()); + if (!File::Delete(segments_to_be_removed_.front().c_str())) { + LOG(WARNING) << "Failed to delete " << segments_to_be_removed_.front() + << "; Will retry later."; + break; + } segments_to_be_removed_.pop_front(); } } diff --git a/packager/mpd/base/representation.cc b/packager/mpd/base/representation.cc index f7b90e84e4..c557f91616 100644 --- a/packager/mpd/base/representation.cc +++ b/packager/mpd/base/representation.cc @@ -500,7 +500,11 @@ void Representation::RemoveSegments(int64_t start_time, while (segments_to_be_removed_.size() > mpd_options_.mpd_params.preserved_segments_outside_live_window) { VLOG(2) << "Deleting " << segments_to_be_removed_.front(); - File::Delete(segments_to_be_removed_.front().c_str()); + if (!File::Delete(segments_to_be_removed_.front().c_str())) { + LOG(WARNING) << "Failed to delete " << segments_to_be_removed_.front() + << "; Will retry later."; + break; + } segments_to_be_removed_.pop_front(); } }