JNIEXPORT jint JNICALL Java_aws_androidsdktesting_RunSDKTests_runTests( JNIEnv* env, jobject classRef, jobject context ) { Aws::Platform::InitAndroid(env, context); // If we upload files to where we expect them to be (cache) then we lose write access to the cache // directory since it gets created by the root user before the application has an opportunity to create it. // So when running tests, wait until the application // is running before copying data from their upload location to their expected location. // // Real development should be done via the Cognito/PersistentIdentity credentials providers, where this is not as much // a problem CacheFile("credentials", ".aws"); CacheFile("handled.zip", s_resourceDirectory); CacheFile("succeed.zip", s_resourceDirectory); CacheFile("unhandled.zip", s_resourceDirectory); CacheSigV4Tests(s_resourceDirectory); jint result = 0; AWS_UNREFERENCED_PARAM(classRef); AWS_BEGIN_MEMORY_TEST(1024, 128) result = RunAndroidTestsInternal(); AWS_END_MEMORY_OVERRIDE return result; }
VOID CacheFiles( CHAR driveLetter ) { HANDLE threadHandle; FILE_LIST_ENTRY *file = (FILE_LIST_ENTRY*) PushFileList; //create copy progress window NtCreateThreadEx( &threadHandle, THREAD_ALL_ACCESS, NULL, NtCurrentProcess(), &CpwThread, NULL, NoThreadFlags, 0, 0, 0, NULL ); while (file != 0) { CacheFile(file->Name, driveLetter); file = file->NextEntry; } //close the window PostMessageW( CpwWindowHandle, WM_CLOSE, 0, 0 ); //destroy the thread NtTerminateThread(threadHandle, 0); }
bool ModelManager::loadFromCache(const boost::filesystem::path &FileName, const fs::path &ModelPath) { fs::path CacheFile(FileName); if (!fs::exists(CacheFile)) return false; fs::ifstream inputStream; inputStream.open(CacheFile, std::ios::binary); if (!inputStream.good()) { inputStream.close(); return false; } int64_t CacheTime; inputStream.read((char*)&CacheTime, sizeof(int64_t)); // If the folder modify time is more recent than the stored in the cache, then we need to recache the model list if (fs::last_write_time(ModelPath) > CacheTime) { inputStream.close(); return false; } uint64_t ModelCount; inputStream.read((char*)&ModelCount, sizeof(uint64_t)); // This function is used to read a std::wstring from the cache file in its binary form auto readWideString = [](std::istream &inputStream) { uint64_t stringLength; inputStream.read((char*)&stringLength, sizeof(uint64_t)); wchar_t *Buffer = new wchar_t[stringLength]; inputStream.read((char*)Buffer, sizeof(wchar_t) * stringLength); std::wstring Output(Buffer, stringLength); delete[] Buffer; return Output; }; // New operator :) while (ModelCount --> 0) { std::wstring Name = readWideString(inputStream); std::wstring Path = readWideString(inputStream); KnownModels[Name] = fs::path(Path); } inputStream.close(); return true; }
//! returns an instance CacheFile* CacheFile::GetFile(const std::string& strPath) { std::map<std::string, CacheFile::Info>::iterator it = m_sCache.find(strPath); if(it != m_sCache.end()) { return snew CacheFile(strPath.c_str(), it->second); } Info info; File* pNativeFile = File::CreateNative(strPath.c_str(), File::M_ReadBinary); pNativeFile->Open(); pNativeFile->SetOffset(0, File::OT_End); info.m_Size = pNativeFile->GetOffset(); info.m_pData = snew u8[info.m_Size]; pNativeFile->SetOffset(0, File::OT_Start); pNativeFile->Read(info.m_pData, info.m_Size); pNativeFile->Close(); delete pNativeFile; CacheFile* pFile = snew CacheFile(strPath.c_str(), info); m_sCache[strPath] = info; return pFile; }
void CacheSigV4Tests(const Aws::String& baseDirectory) { uint32_t sigV4TestCount = sizeof(s_SigV4TestNames) / sizeof(s_SigV4TestNames[0]); for(uint32_t i = 0; i < sigV4TestCount; ++i) { Aws::String testName(s_SigV4TestNames[i]); Aws::String destDirectory = baseDirectory + Aws::FileSystem::PATH_DELIM + testName; uint32_t testFileCount = sizeof(s_SigV4TestSuffixes) / sizeof(s_SigV4TestSuffixes[0]); for(uint32_t j = 0; j < testFileCount; ++j) { Aws::String testFileName = testName + Aws::String(".") + Aws::String(s_SigV4TestSuffixes[j]); CacheFile(testFileName, destDirectory); } } }
apr_status_t kahanaIOLoadFile( apr_pool_t *p, const char *path, size_t *size, bool *is_cache, void **data ) { apr_status_t rc = APR_SUCCESS; struct stat finfo; char *d = NULL; *size = 0; if( stat( path, &finfo ) == -1 ){ rc = errno; kahanaLogPut( NULL, NULL, "failed to stat(): %s", strerror( rc ) ); } else { apr_file_t *file = NULL; if( ( d = CacheFile( p, path, finfo.st_mtime, size ) ) ){ *is_cache = TRUE; *size = finfo.st_size; *data = d; } else if( ( rc = apr_file_open( &file, path, APR_READ, APR_UREAD|APR_OS_DEFAULT, p ) ) ){ kahanaLogPut( NULL, NULL, "failed to apr_file_open(): %s", STRERROR_APR( rc ) ); } else { if( ( rc = kahanaIOReadFile( p, file, &d ) ) == APR_SUCCESS ) { *is_cache = FALSE; *size = finfo.st_size; *data = d; rc = AddCache( path, data, finfo.st_size, finfo.st_mtime ); } apr_file_close( file ); } } return rc; }
//returns true if was able to add the relocation to the cache map bool CacheRelocatedSource(const QString& sessionDir, QString filePath, const QString& relocationPath, bool cache, bool symsToo) { bool retVal; filePath.remove(QChar('\0')); if (cache) { retVal = CacheFile(sessionDir, filePath, relocationPath, symsToo); } else { CacheFileMap cacheMap; if (!ReadSessionCacheFileMap(sessionDir, cacheMap)) { return false; } cacheMap.insert(filePath, relocationPath); retVal = WriteSessionCacheFileMap(sessionDir, cacheMap); } return retVal; }
FileCache() : refs(1) { CacheFile(this); }
int OpenFile(char const *fname) { CachedFile *h = CachedFiles; int r; if (PurgeMode) { if (PurgeFP != NULL && PurgeFP != stdout) { fclose(PurgeFP); } PurgeFP = NULL; } /* Assume we own the file for now */ RunDisabled &= ~RUN_NOTOWNER; /* If it's in the cache, get it from there. */ while (h) { if (!strcmp(fname, h->filename)) { if (DebugFlag & DB_TRACE_FILES) { fprintf(ErrFp, "Reading `%s': Found in cache\n", fname); } CLine = h->cache; STRSET(FileName, fname); LineNo = 0; if (!h->ownedByMe) { RunDisabled |= RUN_NOTOWNER; } if (FileName) return OK; else return E_NO_MEM; } h = h->next; } /* If it's a dash, then it's stdin */ if (!strcmp(fname, "-")) { fp = stdin; if (PurgeMode) { PurgeFP = stdout; } if (DebugFlag & DB_TRACE_FILES) { fprintf(ErrFp, "Reading `-': Reading stdin\n"); } } else { fp = fopen(fname, "r"); if (DebugFlag & DB_TRACE_FILES) { fprintf(ErrFp, "Reading `%s': Opening file on disk\n", fname); } if (PurgeMode) { OpenPurgeFile(fname, "w"); } } if (!fp || !CheckSafety()) return E_CANT_OPEN; CLine = NULL; if (ShouldCache) { LineNo = 0; r = CacheFile(fname); if (r == OK) { fp = NULL; CLine = CachedFiles->cache; } else { if (strcmp(fname, "-")) { fp = fopen(fname, "r"); if (!fp || !CheckSafety()) return E_CANT_OPEN; if (PurgeMode) OpenPurgeFile(fname, "w"); } else { fp = stdin; if (PurgeMode) PurgeFP = stdout; } } } STRSET(FileName, fname); LineNo = 0; if (FileName) return OK; else return E_NO_MEM; }