summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Mohrhard <markus.mohrhard@googlemail.com>2013-09-30 22:43:44 +0200
committerMarkus Mohrhard <markus.mohrhard@googlemail.com>2013-10-01 01:48:06 +0200
commit6c7cc9b637ef77a606d27f62aa5cc7f19550962b (patch)
treecc4500f22c52146c3f28b3b4daa6beb57b708b81
parentd81286b78ff90cf4cde17c5000cd8eda6ea4a380 (diff)
clear cache of old files when opencl source changes
Change-Id: I67bc06f80c284c85d2bb409380ba3a43611ec31c
-rw-r--r--sc/source/core/opencl/openclwrapper.cxx31
1 files changed, 31 insertions, 0 deletions
diff --git a/sc/source/core/opencl/openclwrapper.cxx b/sc/source/core/opencl/openclwrapper.cxx
index 6fa86cc7e6d6..b15dc736b948 100644
--- a/sc/source/core/opencl/openclwrapper.cxx
+++ b/sc/source/core/opencl/openclwrapper.cxx
@@ -92,6 +92,36 @@ OString getCacheFolder()
return rtl::OUStringToOString(url, RTL_TEXTENCODING_UTF8);
}
+void clearCache()
+{
+ OUString aCacheDirURL(rtl::OStringToOUString(OpenclDevice::maCacheFolder, RTL_TEXTENCODING_UTF8));
+ osl::Directory aCacheDir(aCacheDirURL);
+ osl::FileBase::RC status = aCacheDir.open();
+ if(status != osl::FileBase::E_None)
+ return;
+
+ osl::DirectoryItem aItem;
+ OUString aSourceString = rtl::OStringToOUString(OpenclDevice::maSourceHash + ".bin", RTL_TEXTENCODING_UTF8);
+ while(osl::FileBase::E_None == aCacheDir.getNextItem(aItem))
+ {
+ osl::FileStatus aFileStatus(osl_FileStatus_Mask_FileName|osl_FileStatus_Mask_FileURL);
+ status = aItem.getFileStatus(aFileStatus);
+ if(status != osl::FileBase::E_None)
+ continue;
+
+ OUString aFileName = aFileStatus.getFileName();
+ if(aFileName.endsWith(".bin"))
+ {
+ if(!aFileName.endsWith(aSourceString))
+ {
+ // delete the file
+ OUString aFileUrl = aFileStatus.getFileURL();
+ osl::File::remove(aFileUrl);
+ }
+ }
+ }
+}
+
}
OString OpenclDevice::maSourceHash = generateHashForSource();
@@ -259,6 +289,7 @@ std::vector<boost::shared_ptr<osl::File> > OpenclDevice::binaryGenerated( const
int OpenclDevice::writeBinaryToFile( const OString& rFileName, const char* binary, size_t numBytes )
{
+ clearCache();
osl::File file(rtl::OStringToOUString(rFileName, RTL_TEXTENCODING_UTF8));
osl::FileBase::RC status = file.open(
osl_File_OpenFlag_Write | osl_File_OpenFlag_Create );