255: RT does not lock output file while writing by oduis

This commit is contained in:
Andrey Skvortsov
2010-10-15 21:16:02 -07:00
parent 8bc162f408
commit 217aa68350

View File

@@ -410,7 +410,11 @@ int ImageIO::loadTIFF (Glib::ustring fname) {
int ImageIO::savePNG (Glib::ustring fname, int compression, int bps) {
FILE* file=g_fopen(safe_locale_from_utf8(fname).c_str (),"wb");
// create a temporary file name that is opened in parallel by e.g. image viewers whilte RT is still writing
Glib::ustring tmpFname=fname;
tmpFname.append(".tmp");
FILE *file = g_fopen (safe_locale_from_utf8(tmpFname).c_str (), "wb");
if (!file)
return IMIO_CANNOTREADFILE;
@@ -477,6 +481,9 @@ int ImageIO::savePNG (Glib::ustring fname, int compression, int bps) {
delete [] row;
fclose (file);
// Rename temporary filename, practically atomic
rename(safe_locale_from_utf8(tmpFname).c_str (),safe_locale_from_utf8(fname).c_str ());
if (pl) {
pl->setProgressStr ("Ready.");
pl->setProgress (1.0);
@@ -494,7 +501,11 @@ int ImageIO::saveJPEG (Glib::ustring fname, int quality) {
cinfo.err = jpeg_std_error (&jerr);
jpeg_create_compress (&cinfo);
FILE *file = g_fopen (safe_locale_from_utf8(fname).c_str (), "wb");
// create a temporary file name that is opened in parallel by e.g. image viewers whilte RT is still writing
Glib::ustring tmpFname=fname;
tmpFname.append(".tmp");
FILE *file = g_fopen (safe_locale_from_utf8(tmpFname).c_str (), "wb");
if (!file)
return IMIO_CANNOTREADFILE;
@@ -584,6 +595,9 @@ int ImageIO::saveJPEG (Glib::ustring fname, int quality) {
delete [] row;
fclose (file);
// Rename temporary filename, practically atomic
rename(safe_locale_from_utf8(tmpFname).c_str (),safe_locale_from_utf8(fname).c_str ());
if (pl) {
pl->setProgressStr ("Ready.");
pl->setProgress (1.0);