: base_dir(base_dir), name(name_template)
{
if (!base_dir.mkdtemp(name))
- throw runtime_error_with_errno("mkdtemp failed", errno);
+ SN_THROW(IOErrorException(sformat("mkdtmp failed errno:%d (%s)", errno,
+ stringerror(errno).c_str())));
}
{
SDir subdir(base_dir, name);
if (!subdir.mount(device, mount_type, mount_flags, mount_data))
- throw runtime_error_with_errno("mount failed", errno);
+ SN_THROW(IOErrorException(sformat("mount failed errno:%d (%s)", errno,
+ stringerror(errno).c_str())));
}
}
catch (const InvalidKeyException& e)
{
+ SN_CAUGHT(e);
+
SN_THROW(InvalidConfigdataException());
}
}
}
catch (const FileNotFoundException& e)
{
+ SN_CAUGHT(e);
+
SN_THROW(ConfigNotFoundException());
}
}
catch (const UmountSnapshotFailedException& e)
{
+ SN_CAUGHT(e);
}
}
}
catch (const FileNotFoundException& e)
{
+ SN_CAUGHT(e);
+
y2err("config '" << *it << "' not found");
}
catch (const InvalidConfigException& e)
{
+ SN_CAUGHT(e);
+
y2err("config '" << *it << "' is invalid");
}
}
}
catch (const FileNotFoundException& e)
{
+ SN_CAUGHT(e);
+
SN_THROW(ListConfigsFailedException("sysconfig-file not found"));
}
}
catch (const InvalidConfigException& e)
{
+ SN_CAUGHT(e);
+
SN_THROW(CreateConfigFailedException("invalid filesystem type"));
}
catch (const ProgramNotInstalledException& e)
{
+ SN_CAUGHT(e);
+
SN_THROW(CreateConfigFailedException(e.what()));
}
}
catch (const FileNotFoundException& e)
{
+ SN_CAUGHT(e);
+
SN_THROW(CreateConfigFailedException("sysconfig-file not found"));
}
}
catch (const FileNotFoundException& e)
{
+ SN_CAUGHT(e);
+
SN_THROW(CreateConfigFailedException("modifying config failed"));
}
}
catch (const DeleteSnapshotFailedException& e)
{
+ SN_CAUGHT(e);
+
// ignore, Filesystem->deleteConfig will fail anyway
}
}
}
catch (const DeleteConfigFailedException& e)
{
+ SN_CAUGHT(e);
+
SN_THROW(DeleteConfigFailedException("deleting snapshot failed"));
}
}
catch (const FileNotFoundException& e)
{
+ SN_CAUGHT(e);
+
SN_THROW(DeleteConfigFailedException("sysconfig-file not found"));
}
}
{
SDir info_dir(infos_dir, *it1);
int fd = info_dir.open("info.xml", O_NOFOLLOW | O_CLOEXEC);
+ if (fd < 0)
+ SN_THROW(IOErrorException("open info.xml failed"));
+
XmlFile file(fd, "");
const xmlNode* node = file.getRootElement();
entries.push_back(snapshot);
}
- catch (const IOErrorException& e)
+ catch (const Exception& e)
{
+ SN_CAUGHT(e);
+
y2err("loading " << *it1 << " failed");
}
}
}
catch (const IOErrorException& e)
{
+ SN_CAUGHT(e);
+
y2err("reading failed");
}
SDir info_dir = openInfoDir();
- xml.save(info_dir.mktemp(tmp_name));
+ int fd = info_dir.mktemp(tmp_name);
+ if (fd < 0)
+ SN_THROW(IOErrorException("mktemp failed"));
+
+ try
+ {
+ xml.save(fd);
+ }
+ catch (const Exception& e)
+ {
+ SN_CAUGHT(e);
+
+ info_dir.unlink(tmp_name, 0);
+
+ SN_RETHROW(e);
+ }
if (info_dir.rename(tmp_name, file_name) != 0)
+ {
SN_THROW(IOErrorException(sformat("rename info.xml failed infoDir:%s errno:%d (%s)",
info_dir.fullname().c_str(), errno,
stringerror(errno).c_str())));
+ }
info_dir.fsync();
}
/*
* Copyright (c) [2010-2012] Novell, Inc.
- * Copyright (c) 2020 SUSE LLC
+ * Copyright (c) [2020-2022] SUSE LLC
*
* All Rights Reserved.
*
: doc(xmlNewDoc((const xmlChar*) "1.0"))
{
if (!doc)
- throw BadAllocException();
+ SN_THROW(BadAllocException());
}
close(fd);
if (!doc)
- throw IOErrorException("xmlReadFd failed");
+ SN_THROW(IOErrorException("xmlReadFd failed"));
}
: doc(xmlReadFile(filename.c_str(), NULL, XML_PARSE_NOBLANKS | XML_PARSE_NONET))
{
if (!doc)
- throw IOErrorException("xmlReadFile failed");
+ SN_THROW(IOErrorException("xmlReadFile failed"));
}
{
FILE* f = fdopen(fd, "w");
if (!f)
- throw IOErrorException("fdopen");
+ {
+ close(fd);
+ SN_THROW(IOErrorException("fdopen"));
+ }
if (xmlDocFormatDump(f, doc, 1) == -1)
{
fclose(f);
- throw IOErrorException("xmlDocFormatDump failed");
+ SN_THROW(IOErrorException("xmlDocFormatDump failed"));
}
fflush(f);
fsync(fileno(f));
- fclose(f);
+
+ if (fclose(f) != 0)
+ SN_THROW(IOErrorException("fclose failed"));
}
XmlFile::save(const string& filename)
{
if (xmlSaveFormatFile(filename.c_str(), doc, 1) == -1)
- throw IOErrorException("xmlSaveFormatFile failed");
+ SN_THROW(IOErrorException("xmlSaveFormatFile failed"));
}