| 4787 | /************************************************************************/ |
| 4788 | |
| 4789 | static int TestVirtualIO(GDALDataset *poDS) |
| 4790 | { |
| 4791 | int bRet = TRUE; |
| 4792 | |
| 4793 | if (STARTS_WITH(poDS->GetDescription(), "/vsimem/")) |
| 4794 | return TRUE; |
| 4795 | |
| 4796 | VSIStatBufL sStat; |
| 4797 | if (!(VSIStatL(poDS->GetDescription(), &sStat) == 0)) |
| 4798 | return TRUE; |
| 4799 | |
| 4800 | // Don't try with ODBC (will avoid a useless error message in ogr_odbc.py) |
| 4801 | if (poDS->GetDriver() != nullptr && |
| 4802 | EQUAL(poDS->GetDriver()->GetDescription(), "ODBC")) |
| 4803 | { |
| 4804 | return TRUE; |
| 4805 | } |
| 4806 | |
| 4807 | const CPLStringList aosFileList(LOG_ACTION(poDS->GetFileList())); |
| 4808 | CPLString osPath; |
| 4809 | int bAllPathIdentical = TRUE; |
| 4810 | for (const char *pszFilename : aosFileList) |
| 4811 | { |
| 4812 | if (pszFilename == aosFileList[0]) |
| 4813 | osPath = CPLGetPathSafe(pszFilename); |
| 4814 | else if (osPath != CPLGetPathSafe(pszFilename)) |
| 4815 | { |
| 4816 | bAllPathIdentical = FALSE; |
| 4817 | break; |
| 4818 | } |
| 4819 | } |
| 4820 | CPLString osVirtPath; |
| 4821 | if (bAllPathIdentical && aosFileList.size() > 1) |
| 4822 | { |
| 4823 | osVirtPath = |
| 4824 | CPLFormFilenameSafe("/vsimem", CPLGetFilename(osPath), nullptr); |
| 4825 | VSIMkdir(osVirtPath, 0666); |
| 4826 | } |
| 4827 | else |
| 4828 | osVirtPath = "/vsimem"; |
| 4829 | |
| 4830 | for (const char *pszFilename : aosFileList) |
| 4831 | { |
| 4832 | const std::string osDestFile = CPLFormFilenameSafe( |
| 4833 | osVirtPath, CPLGetFilename(pszFilename), nullptr); |
| 4834 | /* CPLDebug("test_ogrsf", "Copying %s to %s", pszFilename, osDestFile.c_str()); |
| 4835 | */ |
| 4836 | CPLCopyFile(osDestFile.c_str(), pszFilename); |
| 4837 | } |
| 4838 | |
| 4839 | std::string osVirtFile; |
| 4840 | if (VSI_ISREG(sStat.st_mode)) |
| 4841 | osVirtFile = CPLFormFilenameSafe( |
| 4842 | osVirtPath, CPLGetFilename(poDS->GetDescription()), nullptr); |
| 4843 | else |
| 4844 | osVirtFile = osVirtPath; |
| 4845 | CPLDebug("test_ogrsf", "Trying to open %s", osVirtFile.c_str()); |
| 4846 | GDALDataset *poDS2 = LOG_ACTION(static_cast<GDALDataset *>(GDALOpenEx( |
no test coverage detected