Fix #5. Use our own function instead of wxRemoveFile, because the latter shows an error when the file doesn't exist.

This commit is contained in:
Twan van Laarhoven
2020-04-28 13:50:06 +02:00
parent ed918ce64f
commit 5f615b3117
5 changed files with 23 additions and 11 deletions
+1 -1
View File
@@ -118,7 +118,7 @@ class TokenIterator {
// ----------------------------------------------------------------------------- : Characters
bool isUnicodeAlpha(Char c) {
#if wxMSW
#if defined(__WXMSW__)
return false;
#else
// libc's iswalpha doesn't work on non-ascii characters. For the parser let's just say that anything >=128 is alphabetic
+7 -2
View File
@@ -148,7 +148,7 @@ class RecursiveDeleter : public wxDirTraverser {
}
wxDirTraverseResult OnFile(const String& filename) {
if (!wxRemoveFile(filename)) {
if (!remove_file(filename)) {
ok = false;
handle_error(_("Cannot delete ") + filename + _("\n")
_("The remainder of the package has still been removed, if possible.\n")
@@ -164,9 +164,14 @@ class RecursiveDeleter : public wxDirTraverser {
vector<String> to_delete;
};
bool remove_file(const String& filename) {
// Based on wxRemoveFile
return wxRemove(filename.fn_str()) == 0;
}
bool remove_file_or_dir(const String& name) {
if (wxFileExists(name)) {
return wxRemoveFile(name);
return remove_file(name);
} else if (wxDirExists(name)) {
RecursiveDeleter rd(name);
{
+6
View File
@@ -48,6 +48,12 @@ time_t file_modified_time(const String& name);
/// Ensure that the parent directories of the given filename exist
bool create_parent_dirs(const String& file);
/// Remove the given file
/** This is identical to wxRemoveFile, except that it doesn't show an error message if the file doesn't exist.
* (who thought that that was a good idea?)
*/
bool remove_file(const String& file);
/// Remove the given file or directory
/** It is not an error if the file doesn't exist.
* Removes all files in a directory.
+7 -7
View File
@@ -29,7 +29,7 @@ Package::~Package() {
// remove any remaining temporary files
FOR_EACH(f, files) {
if (f.second.wasWritten()) {
wxRemoveFile(f.second.tempName);
remove_file(f.second.tempName);
}
}
}
@@ -120,7 +120,7 @@ void Package::removeTempFiles(bool remove_unused) {
while (it != files.end()) {
if (it->second.wasWritten()) {
// remove corresponding temp file
wxRemoveFile(it->second.tempName);
remove_file(it->second.tempName);
}
if (!it->second.keep && remove_unused) {
// also remove the record of deleted files
@@ -370,7 +370,7 @@ void Package::saveToDirectory(const String& saveAs, bool remove_unused, bool is_
vcs->removeFile(saveAs+_("/")+f.first);
} else if (f.second.wasWritten()) {
// move files that were updated
wxRemoveFile(saveAs+_("/")+f.first);
remove_file(saveAs+_("/")+f.first);
if (!(is_copy ? wxCopyFile (f.second.tempName, saveAs+_("/")+f.first)
: wxRenameFile(f.second.tempName, saveAs+_("/")+f.first))) {
throw PackageError(_ERROR_("unable to store file"));
@@ -394,7 +394,7 @@ void Package::saveToDirectory(const String& saveAs, bool remove_unused, bool is_
void Package::saveToZipfile(const String& saveAs, bool remove_unused, bool is_copy) {
// create a temporary zip file name
String tempFile = saveAs + _(".tmp");
wxRemoveFile(tempFile);
remove_file(tempFile);
// open zip file
try {
unique_ptr<wxFileOutputStream> newFile(new wxFileOutputStream(tempFile));
@@ -423,15 +423,15 @@ void Package::saveToZipfile(const String& saveAs, bool remove_unused, bool is_co
if (!is_copy) {
zipStream.reset();
}
} catch (Error e) {
} catch (Error const& e) {
// when things go wrong delete the temp file
wxRemoveFile(tempFile);
remove_file(tempFile);
throw e;
}
// replace the old file with the new file, in effect commiting the changes
if (wxFileExists(saveAs)) {
// rename old file to .bak
wxRemoveFile(saveAs + _(".bak"));
remove_file(saveAs + _(".bak"));
wxRenameFile(saveAs, saveAs + _(".bak"));
}
wxRenameFile(tempFile, saveAs);
+2 -1
View File
@@ -9,6 +9,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <util/file_utils.hpp>
#include <wx/filename.h>
class VCS;
@@ -38,7 +39,7 @@ class VCS : public IntrusivePtrVirtualBase
}
/// Delete a file right off the disk
virtual void removeFile (const wxFileName& filename) {
wxRemoveFile(filename.GetFullName());
remove_file(filename.GetFullName());
}
DECLARE_REFLECTION_VIRTUAL();