mirror of
https://github.com/cookiengineer/audacity
synced 2025-08-03 09:29:30 +02:00
Move MyCopyFile into class FileNames
This commit is contained in:
parent
0c97918bb9
commit
6463e12576
@ -91,6 +91,7 @@
|
|||||||
#include "AudacityException.h"
|
#include "AudacityException.h"
|
||||||
#include "BlockFile.h"
|
#include "BlockFile.h"
|
||||||
#include "FileException.h"
|
#include "FileException.h"
|
||||||
|
#include "FileNames.h"
|
||||||
#include "blockfile/LegacyBlockFile.h"
|
#include "blockfile/LegacyBlockFile.h"
|
||||||
#include "blockfile/LegacyAliasBlockFile.h"
|
#include "blockfile/LegacyAliasBlockFile.h"
|
||||||
#include "blockfile/SimpleBlockFile.h"
|
#include "blockfile/SimpleBlockFile.h"
|
||||||
@ -1161,34 +1162,6 @@ bool DirManager::ContainsBlockFile(const wxString &filepath) const
|
|||||||
BlockFilePtr{ it->second.lock() };
|
BlockFilePtr{ it->second.lock() };
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
|
||||||
bool MyCopyFile(const wxString& file1, const wxString& file2,
|
|
||||||
bool overwrite = true)
|
|
||||||
{
|
|
||||||
#ifdef __WXMSW__
|
|
||||||
|
|
||||||
// workaround not needed
|
|
||||||
return wxCopyFile(file1, file2, overwrite);
|
|
||||||
|
|
||||||
#else
|
|
||||||
// PRL: Compensate for buggy wxCopyFile that returns false success,
|
|
||||||
// which was a cause of case 4 in comment 10 of
|
|
||||||
// http://bugzilla.audacityteam.org/show_bug.cgi?id=1759
|
|
||||||
// Destination file was created, but was empty
|
|
||||||
// Bug was introduced after wxWidgets 2.8.12 at commit
|
|
||||||
// 0597e7f977c87d107e24bf3e95ebfa3d60efc249 of wxWidgets repo
|
|
||||||
|
|
||||||
bool existed = wxFileExists(file2);
|
|
||||||
bool result = wxCopyFile(file1, file2, overwrite) &&
|
|
||||||
wxFile{ file1 }.Length() == wxFile{ file2 }.Length();
|
|
||||||
if (!result && !existed)
|
|
||||||
wxRemoveFile(file2);
|
|
||||||
return result;
|
|
||||||
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Adds one to the reference count of the block file,
|
// Adds one to the reference count of the block file,
|
||||||
// UNLESS it is "locked", then it makes a NEW copy of
|
// UNLESS it is "locked", then it makes a NEW copy of
|
||||||
// the BlockFile.
|
// the BlockFile.
|
||||||
@ -1232,7 +1205,7 @@ BlockFilePtr DirManager::CopyBlockFile(const BlockFilePtr &b)
|
|||||||
//a summary file, so we should check before we copy.
|
//a summary file, so we should check before we copy.
|
||||||
if(b->IsSummaryAvailable())
|
if(b->IsSummaryAvailable())
|
||||||
{
|
{
|
||||||
if( !MyCopyFile(fn.GetFullPath(),
|
if( !FileNames::CopyFile(fn.GetFullPath(),
|
||||||
newFile.GetFullPath()) )
|
newFile.GetFullPath()) )
|
||||||
// Disk space exhaustion, maybe
|
// Disk space exhaustion, maybe
|
||||||
throw FileException{
|
throw FileException{
|
||||||
@ -1384,7 +1357,7 @@ std::pair<bool, wxString> DirManager::CopyToNewProjectDirectory(BlockFile *f)
|
|||||||
bool summaryExisted = f->IsSummaryAvailable();
|
bool summaryExisted = f->IsSummaryAvailable();
|
||||||
auto oldPath = oldFileNameRef.GetFullPath();
|
auto oldPath = oldFileNameRef.GetFullPath();
|
||||||
if (summaryExisted) {
|
if (summaryExisted) {
|
||||||
auto success = MyCopyFile(oldPath, newPath);
|
auto success = FileNames::CopyFile(oldPath, newPath);
|
||||||
if (!success)
|
if (!success)
|
||||||
return { false, {} };
|
return { false, {} };
|
||||||
}
|
}
|
||||||
@ -1415,7 +1388,7 @@ std::pair<bool, wxString> DirManager::CopyToNewProjectDirectory(BlockFile *f)
|
|||||||
//if it doesn't, we can assume it was written to the NEW name, which is fine.
|
//if it doesn't, we can assume it was written to the NEW name, which is fine.
|
||||||
if (oldFileName.FileExists())
|
if (oldFileName.FileExists())
|
||||||
{
|
{
|
||||||
bool ok = MyCopyFile(oldPath, newPath);
|
bool ok = FileNames::CopyFile(oldPath, newPath);
|
||||||
if (!ok)
|
if (!ok)
|
||||||
return { false, {} };
|
return { false, {} };
|
||||||
}
|
}
|
||||||
|
@ -43,6 +43,32 @@ used throughout Audacity into this one place.
|
|||||||
|
|
||||||
static wxString gDataDir;
|
static wxString gDataDir;
|
||||||
|
|
||||||
|
bool FileNames::CopyFile(
|
||||||
|
const wxString& file1, const wxString& file2, bool overwrite)
|
||||||
|
{
|
||||||
|
#ifdef __WXMSW__
|
||||||
|
|
||||||
|
// workaround not needed
|
||||||
|
return wxCopyFile(file1, file2, overwrite);
|
||||||
|
|
||||||
|
#else
|
||||||
|
// PRL: Compensate for buggy wxCopyFile that returns false success,
|
||||||
|
// which was a cause of case 4 in comment 10 of
|
||||||
|
// http://bugzilla.audacityteam.org/show_bug.cgi?id=1759
|
||||||
|
// Destination file was created, but was empty
|
||||||
|
// Bug was introduced after wxWidgets 2.8.12 at commit
|
||||||
|
// 0597e7f977c87d107e24bf3e95ebfa3d60efc249 of wxWidgets repo
|
||||||
|
|
||||||
|
bool existed = wxFileExists(file2);
|
||||||
|
bool result = wxCopyFile(file1, file2, overwrite) &&
|
||||||
|
wxFile{ file1 }.Length() == wxFile{ file2 }.Length();
|
||||||
|
if (!result && !existed)
|
||||||
|
wxRemoveFile(file2);
|
||||||
|
return result;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
wxString FileNames::MkDir(const wxString &Str)
|
wxString FileNames::MkDir(const wxString &Str)
|
||||||
{
|
{
|
||||||
// Behaviour of wxFileName::DirExists() and wxFileName::MkDir() has
|
// Behaviour of wxFileName::DirExists() and wxFileName::MkDir() has
|
||||||
|
@ -23,6 +23,10 @@ class wxArrayString;
|
|||||||
class AUDACITY_DLL_API FileNames
|
class AUDACITY_DLL_API FileNames
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
// This exists to compensate for bugs in wxCopyFile:
|
||||||
|
static bool CopyFile(
|
||||||
|
const wxString& file1, const wxString& file2, bool overwrite = true);
|
||||||
|
|
||||||
static wxString MkDir(const wxString &Str);
|
static wxString MkDir(const wxString &Str);
|
||||||
static wxString TempDir();
|
static wxString TempDir();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user