Browse Source

Cleanup File::createSymbolicLink, try a mingw workaround

tags/v1.9.11
falkTX 6 years ago
parent
commit
8e2a3b4704
1 changed files with 13 additions and 36 deletions
  1. +13
    -36
      source/modules/water/files/File.cpp

+ 13
- 36
source/modules/water/files/File.cpp View File

@@ -940,52 +940,29 @@ bool File::createSymbolicLink (const File& linkFileToCreate, bool overwriteExist
{ {
if (linkFileToCreate.exists()) if (linkFileToCreate.exists())
{ {
if (! linkFileToCreate.isSymbolicLink())
{
// user has specified an existing file / directory as the link
// this is bad! the user could end up unintentionally destroying data
jassertfalse;
return false;
}
// user has specified an existing file / directory as the link
// this is bad! the user could end up unintentionally destroying data
CARLA_SAFE_ASSERT_RETURN(linkFileToCreate.isSymbolicLink(), false);
if (overwriteExisting) if (overwriteExisting)
linkFileToCreate.deleteFile(); linkFileToCreate.deleteFile();
} }
#ifndef CARLA_OS_WIN
// one common reason for getting an error here is that the file already exists
if (symlink (fullPath.toRawUTF8(), linkFileToCreate.getFullPathName().toRawUTF8()) == -1)
{
jassertfalse;
return false;
}
#ifdef CARLA_OS_WIN
typedef BOOLEAN (WINAPI* PFUNC)(LPCTSTR, LPCTSTR, DWORD);
return true;
#elif _MSVC_VER
return CreateSymbolicLink (linkFileToCreate.getFullPathName().toUTF8(),
fullPath.toUTF8(),
isDirectory() ? SYMBOLIC_LINK_FLAG_DIRECTORY : 0) != FALSE;
const PFUNC pfn = (PFUNC)GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "CreateSymbolicLinkA");
return pfn ? pfn(linkFileToCreate.getFullPathName().toRawUTF8(),
fullPath.toRawUTF8(),
isDirectory() ? 0x1 /*SYMBOLIC_LINK_FLAG_DIRECTORY*/ : 0x0) != FALSE
: false;
#else #else
jassertfalse; // symbolic links not supported on this platform!
return false;
// one common reason for getting an error here is that the file already exists
return symlink(fullPath.toRawUTF8(), linkFileToCreate.getFullPathName().toRawUTF8()) != -1;
#endif #endif
} }
#if 0
//=====================================================================================================================
MemoryMappedFile::MemoryMappedFile (const File& file, MemoryMappedFile::AccessMode mode, bool exclusive)
: address (nullptr), range (0, file.getSize()), fileHandle (0)
{
openInternal (file, mode, exclusive);
}
MemoryMappedFile::MemoryMappedFile (const File& file, const Range<int64>& fileRange, AccessMode mode, bool exclusive)
: address (nullptr), range (fileRange.getIntersectionWith (Range<int64> (0, file.getSize()))), fileHandle (0)
{
openInternal (file, mode, exclusive);
}
#endif
//===================================================================================================================== //=====================================================================================================================
#ifdef CARLA_OS_WIN #ifdef CARLA_OS_WIN
namespace WindowsFileHelpers namespace WindowsFileHelpers


Loading…
Cancel
Save