mirror of
https://github.com/ElvishArtisan/rivendell.git
synced 2025-04-13 08:09:49 +02:00
* Fixed bug where wrong ID was used for local maintenance * Updated ChangeLog * Added ability to run macros from cart list with "Run Macro" button * Updated ChangeLog * Updated translations * 2018-10-18 Fred Gleason <fredg@paravelsystems.com> * Tweaked the position of buttons on the bottom row of the main screen of rdlibrary(1). * Changed the minimum size of the main screen of rdlibrary to 850x600. * 2018-10-18 Fred Gleason <fredg@paravelsystems.com> * Fixed a regression in rdmaint(8) that broke cut rehashing. * 2018-10-19 Fred Gleason <fredg@paravelsystems.com> * Added code in the %post and %preun rules in 'rivendell.spec.in' to enable and disable the 'rivendell' service. * 2018-10-19 Fred Gleason <fredg@paravelsystems.com> * Modified rdservice(8) to log errors to syslog. * Added an rdservice(8) man page. * Modified 'systemd/rivendell.service.in' to enable automatic start retries. * 2018-10-19 Fred Gleason <fredg@paravelsystems.com> * Fixed a typo that broke generation of the rmlsend(1) man page. * 2018-10-19 Fred Gleason <fredg@paravelsystems.com> * Removed 'build_win32.bat'. * Removed all conditional compilation based on 'WIN32'. * 2018-10-19 Fred Gleason <fredg@paravelsystems.com> * Removed check for Win32 installer from 'configure.ac'. * Removed win32 clauses from '.pro' files.
89 lines
2.1 KiB
C++
89 lines
2.1 KiB
C++
// rdtempdirectory.cpp
|
|
//
|
|
// Securely create and then remove a temporary directory
|
|
//
|
|
// (C) Copyright 2017-2018 Fred Gleason <fredg@paravelsystems.com>
|
|
//
|
|
// This program is free software; you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License version 2 as
|
|
// published by the Free Software Foundation.
|
|
//
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public
|
|
// License along with this program; if not, write to the Free Software
|
|
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
//
|
|
|
|
#include <errno.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
|
|
#include <qdatetime.h>
|
|
#include <qstringlist.h>
|
|
|
|
#include "rdconfig.h"
|
|
#include "rdtempdirectory.h"
|
|
|
|
RDTempDirectory::RDTempDirectory(const QString &base_name)
|
|
{
|
|
temp_base_name=base_name;
|
|
temp_dir=NULL;
|
|
}
|
|
|
|
|
|
RDTempDirectory::~RDTempDirectory()
|
|
{
|
|
if(temp_dir!=NULL) {
|
|
QStringList files=temp_dir->entryList(QDir::Files);
|
|
for(int i=0;i<files.size();i++) {
|
|
temp_dir->remove(files[i]);
|
|
}
|
|
temp_dir->rmdir(temp_dir->path());
|
|
delete temp_dir;
|
|
}
|
|
}
|
|
|
|
|
|
QString RDTempDirectory::path() const
|
|
{
|
|
if(temp_dir==NULL) {
|
|
return QString();
|
|
}
|
|
return temp_dir->path();
|
|
}
|
|
|
|
|
|
bool RDTempDirectory::create(QString *err_msg)
|
|
{
|
|
char tempdir[PATH_MAX];
|
|
|
|
strncpy(tempdir,RDTempDirectory::basePath(),PATH_MAX);
|
|
strncat(tempdir,"/",PATH_MAX-strlen(tempdir));
|
|
strncat(tempdir,temp_base_name,PATH_MAX-strlen(tempdir));
|
|
strncat(tempdir,"XXXXXX",PATH_MAX-strlen(tempdir));
|
|
if(mkdtemp(tempdir)==NULL) {
|
|
*err_msg=strerror(errno);
|
|
return false;
|
|
}
|
|
temp_dir=new QDir(tempdir);
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
QString RDTempDirectory::basePath()
|
|
{
|
|
QString conf_temp_directory = RDConfiguration()->tempDirectory();
|
|
if (!conf_temp_directory.isEmpty()) {
|
|
return conf_temp_directory;
|
|
}
|
|
if(getenv("TMPDIR")!=NULL) {
|
|
return QString(getenv("TMPDIR"));
|
|
}
|
|
return QString("/tmp");
|
|
}
|