Skip to content

Commit 47b393b

Browse files
committed
Fix preserve mtimes for Opus files
1 parent 5c1bc20 commit 47b393b

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

src/scan.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,10 @@ bool ScanJob::Track::scan(const Config &config, std::mutex *m)
213213
SwrContext *swr = nullptr;
214214
AVFormatContext *format_ctx = nullptr;
215215
const AVStream *stream = nullptr;
216+
if (config.preserve_mtimes) {
217+
mtime = std::make_unique<std::filesystem::file_time_type>();
218+
*mtime = std::filesystem::last_write_time(path);
219+
}
216220

217221
// For Opus files, FFmpeg always adjusts the decoded audio samples by the header output
218222
// gain with no way to disable. To get the actual loudness of the audio signal,

src/scan.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class ScanJob {
5353
std::filesystem::path path;
5454
FileType type;
5555
std::unique_ptr<ebur128_state, decltype(&free_ebur128)> ebur128;
56+
std::unique_ptr<std::filesystem::file_time_type> mtime;
5657
std::string container;
5758
ScanResult result;
5859
int codec_id;

src/tag.cpp

+2-6
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,6 @@ static_assert((size_t) R128Tag::MAX_VAL == R128_STRING.size());
168168

169169
void tag_track(ScanJob::Track &track, const Config &config)
170170
{
171-
std::filesystem::file_time_type mtime;
172-
if (config.preserve_mtimes)
173-
mtime = std::filesystem::last_write_time(track.path);
174-
175171
switch (track.type) {
176172
case FileType::MP2:
177173
case FileType::MP3:
@@ -257,8 +253,8 @@ void tag_track(ScanJob::Track &track, const Config &config)
257253
default:
258254
break;
259255
}
260-
if (config.preserve_mtimes)
261-
std::filesystem::last_write_time(track.path, mtime);
256+
if (track.mtime)
257+
std::filesystem::last_write_time(track.path, *(track.mtime));
262258
}
263259

264260
bool tag_exists(const ScanJob::Track &track)

0 commit comments

Comments
 (0)