Bugfix: tilde expansion wasn't working on layout write

This commit is contained in:
Matthias Koefferlein 2023-07-15 13:37:07 +02:00
parent 0b50d9e87a
commit 563f1026e8
2 changed files with 33 additions and 21 deletions

View File

@ -1034,8 +1034,8 @@ OutputStream::seek (size_t pos)
// ---------------------------------------------------------------
// OutputFileBase implementation
OutputFileBase::OutputFileBase (const std::string &path, int keep_backups)
: m_keep_backups (keep_backups), m_path (tl::absolute_file_path (path)), m_has_error (false)
OutputFileBase::OutputFileBase (const std::string &p, int keep_backups)
: m_keep_backups (keep_backups), m_path (tl::absolute_file_path (p)), m_has_error (false)
{
if (tl::file_exists (m_path)) {
m_backup_path = m_path + ".~backup";
@ -1133,20 +1133,19 @@ void OutputFileBase::reject ()
// ---------------------------------------------------------------
// OutputFile implementation
OutputFile::OutputFile (const std::string &path, int keep_backups)
: OutputFileBase (path, keep_backups), m_fd (-1)
OutputFile::OutputFile (const std::string &p, int keep_backups)
: OutputFileBase (p, keep_backups), m_fd (-1)
{
m_source = path;
#if defined(_WIN32)
int fd = _wopen (tl::to_wstring (path).c_str (), _O_CREAT | _O_TRUNC | _O_BINARY | _O_WRONLY | _O_SEQUENTIAL, _S_IREAD | _S_IWRITE );
int fd = _wopen (tl::to_wstring (path ()).c_str (), _O_CREAT | _O_TRUNC | _O_BINARY | _O_WRONLY | _O_SEQUENTIAL, _S_IREAD | _S_IWRITE );
if (fd < 0) {
throw FileOpenErrorException (m_source, errno);
throw FileOpenErrorException (path (), errno);
}
m_fd = fd;
#else
int fd = open (path.c_str (), O_WRONLY | O_CREAT | O_TRUNC, 0666);
int fd = open (path ().c_str (), O_WRONLY | O_CREAT | O_TRUNC, 0666);
if (fd < 0) {
throw FileOpenErrorException (m_source, errno);
throw FileOpenErrorException (path (), errno);
}
m_fd = fd;
#endif
@ -1187,28 +1186,27 @@ OutputFile::write_file (const char *b, size_t n)
ptrdiff_t ret = ::write (m_fd, b, (unsigned int) n);
#endif
if (ret < 0) {
throw FileWriteErrorException (m_source, errno);
throw FileWriteErrorException (path (), errno);
}
}
// ---------------------------------------------------------------
// OutputZLibFile implementation
OutputZLibFile::OutputZLibFile (const std::string &path, int keep_backups)
: OutputFileBase (path, keep_backups), mp_d (new ZLibFilePrivate ())
OutputZLibFile::OutputZLibFile (const std::string &p, int keep_backups)
: OutputFileBase (p, keep_backups), mp_d (new ZLibFilePrivate ())
{
m_source = path;
#if defined(_WIN32)
FILE *file = _wfopen (tl::to_wstring (path).c_str (), L"wb");
FILE *file = _wfopen (tl::to_wstring (path ()).c_str (), L"wb");
if (file == NULL) {
throw FileOpenErrorException (m_source, errno);
throw FileOpenErrorException (path (), errno);
}
mp_d->zs = gzdopen (_fileno (file), "wb");
#else
mp_d->zs = gzopen (tl::string_to_system (path).c_str (), "wb");
mp_d->zs = gzopen (tl::string_to_system (path ()).c_str (), "wb");
#endif
if (mp_d->zs == NULL) {
throw FileOpenErrorException (m_source, errno);
throw FileOpenErrorException (path (), errno);
}
}
@ -1231,9 +1229,9 @@ OutputZLibFile::write_file (const char *b, size_t n)
int gz_err = 0;
const char *em = gzerror (mp_d->zs, &gz_err);
if (gz_err == Z_ERRNO) {
throw FileWriteErrorException (m_source, errno);
throw FileWriteErrorException (path (), errno);
} else {
throw ZLibWriteErrorException (m_source, em);
throw ZLibWriteErrorException (path (), em);
}
}
}

View File

@ -928,6 +928,22 @@ public:
*/
virtual void reject ();
/**
* @brief Gets the actual path
*/
const std::string &path () const
{
return m_path;
}
/**
* @brief Gets the path of the backup file
*/
const std::string &backup_path () const
{
return m_backup_path;
}
protected:
virtual void seek_file (size_t s) = 0;
virtual void write_file (const char *b, size_t n) = 0;
@ -990,7 +1006,6 @@ private:
OutputZLibFile (const OutputZLibFile &);
OutputZLibFile &operator= (const OutputZLibFile &);
std::string m_source;
ZLibFilePrivate *mp_d;
};
@ -1051,7 +1066,6 @@ private:
OutputFile (const OutputFile &);
OutputFile &operator= (const OutputFile &);
std::string m_source;
int m_fd;
};