X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/c3396917e888355d3e7060cbb238a66339d8feb5..4a45223c970eabf6ba66347129627775935c90b3:/src/common/filefn.cpp diff --git a/src/common/filefn.cpp b/src/common/filefn.cpp index b8ceb922f1..4cfc2036a1 100644 --- a/src/common/filefn.cpp +++ b/src/common/filefn.cpp @@ -996,8 +996,15 @@ wxConcatFiles (const wxString& file1, const wxString& file2, const wxString& fil // Copy files bool -wxCopyFile (const wxString& file1, const wxString& file2) +wxCopyFile (const wxString& file1, const wxString& file2, bool overwrite) { +#if defined(__WIN32__) + // CopyFile() copies file attributes and modification time too, so use it + // instead of our code if available + // + // NB: 3rd parameter is bFailIfExists i.e. the inverse of overwrite + return ::CopyFile(file1, file2, !overwrite) != 0; +#else // !Win32 wxStructStat fbuf; // get permissions of file1 @@ -1017,7 +1024,7 @@ wxCopyFile (const wxString& file1, const wxString& file2) // remove file2, if it exists. This is needed for creating // file2 with the correct permissions in the next step - if ( wxFileExists(file2) && !wxRemoveFile(file2) ) + if ( wxFileExists(file2) && (!overwrite || !wxRemoveFile(file2))) { wxLogSysError(_("Impossible to overwrite the file '%s'"), file2.c_str()); @@ -1033,7 +1040,7 @@ wxCopyFile (const wxString& file1, const wxString& file2) // create file2 with the same permissions than file1 and open it for // writing wxFile fileOut; - if ( !fileOut.Create(file2, TRUE, fbuf.st_mode & 0777) ) + if ( !fileOut.Create(file2, overwrite, fbuf.st_mode & 0777) ) return FALSE; #ifdef __UNIX__ @@ -1058,16 +1065,25 @@ wxCopyFile (const wxString& file1, const wxString& file2) return FALSE; } -#if !defined(__VISAGECPP__) && !defined(__WXMAC__) -// no chmod in VA. SHould be some permission API for HPFS386 partitions however + // we can expect fileIn to be closed successfully, but we should ensure + // that fileOut was closed as some write errors (disk full) might not be + // detected before doing this + if ( !fileIn.Close() || !fileOut.Close() ) + return FALSE; + +#if !defined(__VISAGECPP__) && !defined(__WXMAC__) || defined(__UNIX__) + // no chmod in VA. Should be some permission API for HPFS386 partitions + // however if ( chmod(OS_FILENAME(file2), fbuf.st_mode) != 0 ) { wxLogSysError(_("Impossible to set permissions for the file '%s'"), file2.c_str()); return FALSE; } -#endif +#endif // OS/2 || Mac + return TRUE; +#endif // __WXMSW__ && __WIN32__ } bool @@ -1099,7 +1115,7 @@ bool wxRemoveFile(const wxString& file) bool wxMkdir(const wxString& dir, int perm) { -#if defined( __WXMAC__ ) +#if defined(__WXMAC__) && !defined(__UNIX__) return (mkdir(wxUnix2MacFilename( dir ) , 0 ) == 0); #else // !Mac const wxChar *dirname = dir.c_str(); @@ -1664,7 +1680,7 @@ wxChar *wxGetWorkingDirectory(wxChar *buf, int sz) char *cbuf = new char[sz+1]; #ifdef _MSC_VER if (_getcwd(cbuf, sz) == NULL) { -#elif defined( __WXMAC__) +#elif defined(__WXMAC__) && !defined(__UNIX__) enum { SFSaveDisk = 0x214, CurDirStore = 0x398 @@ -1682,7 +1698,7 @@ wxChar *wxGetWorkingDirectory(wxChar *buf, int sz) #else // wxUnicode #ifdef _MSC_VER if (_getcwd(buf, sz) == NULL) { -#elif defined( __WXMAC__) +#elif defined(__WXMAC__) && !defined(__UNIX__) FSSpec cwdSpec ; FCBPBRec pb; OSErr error;