Proper use of MODE_WRITE (which should open a file for appending) and MODE_CREATE (which should truncate existing files). Fixes the "chapter files might contain garbage at the end if an older file was overwritten with a smaller one" problem.

This commit is contained in:
Moritz Bunkus 2005-01-30 18:28:07 +00:00
parent be3a33848b
commit c10d088868
6 changed files with 14 additions and 8 deletions

View File

@ -1,3 +1,9 @@
2005-01-30 Moritz Bunkus <moritz@bunkus.org>
* mmg: bug fix: Overwriting a chapter file did not erase the
previous file. So if the previous file was bigger than the current
chapters then garbage remained at the end of the file.
2005-01-20 Moritz Bunkus <moritz@bunkus.org>
* mmg: bug fix: The "stretch" input box tooltip was wrong. The

View File

@ -82,7 +82,7 @@ main(int argc,
}
try {
out = new mm_file_io_c(argv[3], MODE_WRITE);
out = new mm_file_io_c(argv[3], MODE_CREATE);
} catch(...) {
mxerror(_("The file '%s' could not be opened for writing (%d, %s).\n"),
argv[3], errno, strerror(errno));

View File

@ -44,13 +44,13 @@ mm_file_io_c::mm_file_io_c(const string &path,
cmode = "rb";
break;
case MODE_WRITE:
cmode = "wb";
cmode = "a+b";
break;
case MODE_CREATE:
cmode = "wb+";
cmode = "w+b";
break;
case MODE_SAFE:
cmode = "r+b";
cmode = "rb";
break;
default:
throw 0;
@ -122,7 +122,7 @@ mm_file_io_c::truncate(int64_t pos) {
return ftruncate(fileno((FILE *)file), pos);
}
#else // SYS_UNIX
#else // SYS_WINDOWS
HANDLE
CreateFileUtf8(LPCSTR lpFileName,

View File

@ -130,7 +130,7 @@ handle_attachments(KaxAttachments *atts) {
"is written to '%s'.\n"), id, type.c_str(), size,
tracks[k].out_name);
try {
out = new mm_file_io_c(tracks[k].out_name, MODE_WRITE);
out = new mm_file_io_c(tracks[k].out_name, MODE_CREATE);
} catch (...) {
mxerror(_("The file '%s' could not be opened for writing "
"(%d, %s).\n"),

View File

@ -1278,7 +1278,7 @@ write_all_cuesheets(KaxChapters &chapters,
cue_file_name += ".cue";
try {
out = new mm_file_io_c(cue_file_name.c_str(), MODE_WRITE);
out = new mm_file_io_c(cue_file_name.c_str(), MODE_CREATE);
} catch(...) {
mxerror(_("The file '%s' could not be opened for writing (%s).\n"),
cue_file_name.c_str(), strerror(errno));

View File

@ -778,7 +778,7 @@ tab_chapters::save() {
wxString err;
try {
out = new mm_file_io_c(wxMB(file_name), MODE_WRITE);
out = new mm_file_io_c(wxMB(file_name), MODE_CREATE);
#if defined(SYS_WINDOWS)
out->use_dos_style_newlines(true);
#endif