// 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
// 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());
// 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__
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
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();
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
#else // wxUnicode
#ifdef _MSC_VER
if (_getcwd(buf, sz) == NULL) {
-#elif defined( __WXMAC__)
+#elif defined(__WXMAC__) && !defined(__UNIX__)
FSSpec cwdSpec ;
FCBPBRec pb;
OSErr error;