1204 |
// save the file as separate temporary file first, |
// save the file as separate temporary file first, |
1205 |
// then move the saved file over the old file |
// then move the saved file over the old file |
1206 |
// (may result in performance speedup during save) |
// (may result in performance speedup during save) |
1207 |
String tmpname = filename + ".TMP"; |
gig::String tmpname = filename + ".TMP"; |
1208 |
gig->Save(tmpname, &progress); |
gig->Save(tmpname, &progress); |
1209 |
#if defined(WIN32) |
#if defined(WIN32) |
1210 |
if (!DeleteFile(filename.c_str())) { |
if (!DeleteFile(filename.c_str())) { |
1212 |
} |
} |
1213 |
#else // POSIX ... |
#else // POSIX ... |
1214 |
if (unlink(filename.c_str())) { |
if (unlink(filename.c_str())) { |
1215 |
throw RIFF::Exception("Could not replace original file with temporary file (unable to remove original file): " + String(strerror(errno))); |
throw RIFF::Exception("Could not replace original file with temporary file (unable to remove original file): " + gig::String(strerror(errno))); |
1216 |
} |
} |
1217 |
#endif |
#endif |
1218 |
if (rename(tmpname.c_str(), filename.c_str())) { |
if (rename(tmpname.c_str(), filename.c_str())) { |
1219 |
#if defined(WIN32) |
#if defined(WIN32) |
1220 |
throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file)."); |
throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file)."); |
1221 |
#else |
#else |
1222 |
throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file): " + String(strerror(errno))); |
throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file): " + gig::String(strerror(errno))); |
1223 |
#endif |
#endif |
1224 |
} |
} |
1225 |
} |
} |