static bool ensureDatabaseFileExists(const String& fileName, bool createIfDoesNotExist) { if (createIfDoesNotExist) return makeAllDirectories(directoryName(fileName)); return fileExists(fileName); }
void DatabaseProcess::ensurePathExists(const String& path) { ASSERT(!RunLoop::isMain()); if (!makeAllDirectories(path)) LOG_ERROR("Failed to make all directories for path '%s'", path.utf8().data()); }
static bool makeAllDirectories(IFileMgr* fileManager, const String& path) { if (path == canonicalPath(AEEFS_HOME_DIR)) return true; int lastDivPos = path.reverseFind('/'); int endPos = path.length(); if (lastDivPos == path.length() - 1) { endPos -= 1; lastDivPos = path.reverseFind('/', lastDivPos); } if (lastDivPos > 0) { if (!makeAllDirectories(fileManager, path.substring(0, lastDivPos))) return false; } String folder(path.substring(0, endPos)); // IFILEMGR_MkDir return SUCCESS when the file is successfully created or if file already exists. // So we need to check fileinfo.attrib. IFILEMGR_MkDir(fileManager, folder.utf8().data()); FileInfo fileInfo; if (IFILEMGR_GetInfo(fileManager, folder.utf8().data(), &fileInfo) != SUCCESS) return false; return fileInfo.attrib & _FA_DIR; }
static PassRefPtr<IDBSQLiteDatabase> openSQLiteDatabase(SecurityOrigin* securityOrigin, const String& pathBase, int64_t maximumSize, const String& fileIdentifier, IDBFactoryBackendImpl* factory) { String path = ":memory:"; if (!pathBase.isEmpty()) { if (!makeAllDirectories(pathBase)) { // FIXME: Is there any other thing we could possibly do to recover at this point? If so, do it rather than just erroring out. LOG_ERROR("Unabled to create LocalStorage database path %s", pathBase.utf8().data()); return 0; } path = pathByAppendingComponent(pathBase, securityOrigin->databaseIdentifier() + ".indexeddb"); } RefPtr<IDBSQLiteDatabase> sqliteDatabase = IDBSQLiteDatabase::create(fileIdentifier, factory); if (!sqliteDatabase->db().open(path)) { // FIXME: Is there any other thing we could possibly do to recover at this point? If so, do it rather than just erroring out. LOG_ERROR("Failed to open database file %s for IndexedDB", path.utf8().data()); return 0; } // FIXME: Error checking? sqliteDatabase->db().setMaximumSize(maximumSize); sqliteDatabase->db().turnOnIncrementalAutoVacuum(); return sqliteDatabase.release(); }
String LocalStorageDatabaseTracker::databasePath(const String& filename) const { if (!makeAllDirectories(m_localStorageDirectory)) { LOG_ERROR("Unable to create LocalStorage database path %s", m_localStorageDirectory.utf8().data()); return String(); } return pathByAppendingComponent(m_localStorageDirectory, filename); }
// Called on a background thread. String StorageSyncManager::fullDatabaseFilename(const String& databaseIdentifier) { if (!makeAllDirectories(m_path)) { LOG_ERROR("Unabled to create LocalStorage database path %s", m_path.utf8().data()); return String(); } return pathByAppendingComponent(m_path, databaseIdentifier + ".localstorage"); }
bool SQLiteFileSystem::ensureDatabaseDirectoryExists(const std::string& path) { DLOG(INFO) << ">>>"; if (path.empty()) { DLOG(INFO) << "<<< " << "FALSE"; return false; } DLOG(INFO) << "<<<"; return makeAllDirectories(path); }
static String storageDirectory(DWORD pathIdentifier) { Vector<UChar> buffer(MAX_PATH); if (FAILED(SHGetFolderPathW(0, pathIdentifier | CSIDL_FLAG_CREATE, 0, 0, buffer.data()))) return String(); buffer.resize(wcslen(buffer.data())); String directory = String::adopt(buffer); static const String companyNameDirectory = "Apple Computer\\"; directory = pathByAppendingComponent(directory, companyNameDirectory + bundleName()); if (!makeAllDirectories(directory)) return String(); return directory; }
void ApplicationCacheStorage::openDatabase(bool createIfDoesNotExist) { if (m_database.isOpen()) return; // The cache directory should never be null, but if it for some weird reason is we bail out. if (m_cacheDirectory.isNull()) return; String applicationCachePath = pathByAppendingComponent(m_cacheDirectory, "ApplicationCache.db"); if (!createIfDoesNotExist && !fileExists(applicationCachePath)) return; makeAllDirectories(m_cacheDirectory); m_database.open(applicationCachePath); if (!m_database.isOpen()) return; verifySchemaVersion(); // Create tables executeSQLCommand("CREATE TABLE IF NOT EXISTS CacheGroups (id INTEGER PRIMARY KEY AUTOINCREMENT, " "manifestHostHash INTEGER NOT NULL ON CONFLICT FAIL, manifestURL TEXT UNIQUE ON CONFLICT FAIL, newestCache INTEGER)"); executeSQLCommand("CREATE TABLE IF NOT EXISTS Caches (id INTEGER PRIMARY KEY AUTOINCREMENT, cacheGroup INTEGER)"); executeSQLCommand("CREATE TABLE IF NOT EXISTS CacheWhitelistURLs (url TEXT NOT NULL ON CONFLICT FAIL, cache INTEGER NOT NULL ON CONFLICT FAIL)"); executeSQLCommand("CREATE TABLE IF NOT EXISTS FallbackURLs (namespace TEXT NOT NULL ON CONFLICT FAIL, fallbackURL TEXT NOT NULL ON CONFLICT FAIL, " "cache INTEGER NOT NULL ON CONFLICT FAIL)"); executeSQLCommand("CREATE TABLE IF NOT EXISTS CacheEntries (cache INTEGER NOT NULL ON CONFLICT FAIL, type INTEGER, resource INTEGER NOT NULL)"); executeSQLCommand("CREATE TABLE IF NOT EXISTS CacheResources (id INTEGER PRIMARY KEY AUTOINCREMENT, url TEXT NOT NULL ON CONFLICT FAIL, " "statusCode INTEGER NOT NULL, responseURL TEXT NOT NULL, mimeType TEXT, textEncodingName TEXT, headers TEXT, data INTEGER NOT NULL ON CONFLICT FAIL)"); executeSQLCommand("CREATE TABLE IF NOT EXISTS CacheResourceData (id INTEGER PRIMARY KEY AUTOINCREMENT, data BLOB)"); // When a cache is deleted, all its entries and its whitelist should be deleted. executeSQLCommand("CREATE TRIGGER IF NOT EXISTS CacheDeleted AFTER DELETE ON Caches" " FOR EACH ROW BEGIN" " DELETE FROM CacheEntries WHERE cache = OLD.id;" " DELETE FROM CacheWhitelistURLs WHERE cache = OLD.id;" " DELETE FROM FallbackURLs WHERE cache = OLD.id;" " END"); // When a cache resource is deleted, its data blob should also be deleted. executeSQLCommand("CREATE TRIGGER IF NOT EXISTS CacheResourceDeleted AFTER DELETE ON CacheResources" " FOR EACH ROW BEGIN" " DELETE FROM CacheResourceData WHERE id = OLD.data;" " END"); }
void CookieManager::setCookieJarPath(const String& cookieDirectory) { if (m_backingStore.get()) m_backingStore.clear(); StringBuilder fileName; fileName.append(cookieDirectory); if (!cookieDirectory.isEmpty() && !cookieDirectory.endsWith("/")) fileName.append("/"); makeAllDirectories(fileName.toString()); fileName.append("cookies.db"); m_cookieJarFileName = fileName.toString(); m_backingStore = WTF::adoptPtr(new CookieDatabaseBackingStore(m_cookieJarFileName, m_tree.get())); }
void PluginDatabase::updatePersistentMetadataCache() { if (!isPersistentMetadataCacheEnabled() || persistentMetadataCachePath().isEmpty()) return; makeAllDirectories(persistentMetadataCachePath()); String absoluteCachePath = pathByAppendingComponent(persistentMetadataCachePath(), persistentPluginMetadataCacheFilename); deleteFile(absoluteCachePath); if (m_plugins.isEmpty()) return; PlatformFileHandle file; file = openFile(absoluteCachePath, OpenForWrite); if (!isHandleValid(file)) { LOG_ERROR("Unable to open plugin metadata cache for saving"); return; } char localSchemaVersion = schemaVersion; if (writeToFile(file, &localSchemaVersion, 1) != 1) { LOG_ERROR("Unable to write plugin metadata cache schema"); closeFile(file); deleteFile(absoluteCachePath); return; } PluginSet::const_iterator end = m_plugins.end(); for (PluginSet::const_iterator it = m_plugins.begin(); it != end; ++it) { if (!(writeUTF8String(file, (*it)->path()) && writeTime(file, (*it)->lastModified()) && writeUTF8String(file, (*it)->name()) && writeUTF8String(file, (*it)->description()) && writeUTF8String(file, (*it)->fullMIMEDescription()))) { LOG_ERROR("Unable to write plugin metadata to cache"); closeFile(file); deleteFile(absoluteCachePath); return; } } closeFile(file); }
static String storageDirectory(DWORD pathIdentifier) { #if OS(WINCE) return String(); #else Vector<UChar> buffer(MAX_PATH); if (FAILED(SHGetFolderPathW(0, pathIdentifier | CSIDL_FLAG_CREATE, 0, 0, buffer.data()))) return String(); buffer.resize(wcslen(buffer.data())); String directory = String::adopt(buffer); DEFINE_STATIC_LOCAL(String, companyNameDirectory, (ASCIILiteral("Apple Computer\\"))); directory = pathByAppendingComponent(directory, companyNameDirectory + bundleName()); if (!makeAllDirectories(directory)) return String(); return directory; #endif }
/*SISO_HTMLCOMPOSER begin*/ CString openLocalFile(const String& basePath, const String& extension , PlatformFileHandle& handle) { int number = rand() % 10000 + 1; CString filename; do { StringBuilder builder; builder.append(basePath); if(!fileExists(String("/sdcard/temp"))) { bool ret = makeAllDirectories(String("/sdcard/temp/")); } filename = builder.toString().utf8(); const char* fstr = filename.data(); handle = open(filename.data(), O_WRONLY | O_CREAT /*| O_EXCL*/, S_IRUSR | S_IWUSR); number++; if (handle != -1) return filename; } while (errno == EEXIST); return CString(); }
bool makeAllDirectories(const String& path) { int lastDivPos = max(path.reverseFind('/'), path.reverseFind('\\')); int endPos = path.length(); if (lastDivPos == path.length() - 1) { endPos -= 1; lastDivPos = max(path.reverseFind('/', lastDivPos), path.reverseFind('\\', lastDivPos)); } if (lastDivPos > 0) { if (!makeAllDirectories(path.substring(0, lastDivPos))) return false; } String folder(path.substring(0, endPos)); CreateDirectory(folder.charactersWithNullTermination(), 0); DWORD fileAttr = GetFileAttributes(folder.charactersWithNullTermination()); return fileAttr != 0xFFFFFFFF && (fileAttr & FILE_ATTRIBUTE_DIRECTORY); }
bool makeAllDirectories(const String& path) { size_t lastDivPos = reverseFindPathSeparator(path); unsigned endPos = path.length(); if (lastDivPos == endPos - 1) { --endPos; lastDivPos = reverseFindPathSeparator(path, lastDivPos); } if (lastDivPos != notFound) { if (!makeAllDirectories(path.substring(0, lastDivPos))) return false; } String folder(path.substring(0, endPos)); CreateDirectory(folder.charactersWithNullTermination(), 0); DWORD fileAttr = GetFileAttributes(folder.charactersWithNullTermination()); return fileAttr != 0xFFFFFFFF && (fileAttr & FILE_ATTRIBUTE_DIRECTORY); }
String LocalStorage::fullDatabaseFilename(SecurityOrigin* origin) { // FIXME: Once we actually track origin/quota entries to see which origins have local storage established, // we will return an empty path name if the origin isn't allowed to have LocalStorage. // We'll need to wait here until the AreaImport task to complete before making that decision. if (m_path.isEmpty()) return String(); ASSERT(origin); if (!origin) return String(); if (!makeAllDirectories(m_path)) { LOG_ERROR("Unabled to create LocalStorage database path %s", m_path.utf8().data()); return String(); } return pathByAppendingComponent(m_path, origin->databaseIdentifier() + ".localstorage"); }
void WebResourceLoadStatisticsStore::writeEncoderToDisk(KeyedEncoder& encoder, const String& label) const { RefPtr<SharedBuffer> rawData = encoder.finishEncoding(); if (!rawData) return; String resourceLog = persistentStoragePath(label); if (resourceLog.isEmpty()) return; if (!m_storagePath.isEmpty()) makeAllDirectories(m_storagePath); auto handle = openFile(resourceLog, OpenForWrite); if (!handle) return; int64_t writtenBytes = writeToFile(handle, rawData->data(), rawData->size()); closeFile(handle); if (writtenBytes != static_cast<int64_t>(rawData->size())) WTFLogAlways("WebResourceLoadStatisticsStore: We only wrote %d out of %d bytes to disk", static_cast<unsigned>(writtenBytes), rawData->size()); }
static PassOwnPtr<SQLiteDatabase> openSQLiteDatabase(SecurityOrigin* securityOrigin, String name, const String& pathBase, int64_t maximumSize) { String path = ":memory:"; if (!pathBase.isEmpty()) { if (!makeAllDirectories(pathBase)) { // FIXME: Is there any other thing we could possibly do to recover at this point? If so, do it rather than just erroring out. LOG_ERROR("Unabled to create LocalStorage database path %s", pathBase.utf8().data()); return 0; } path = pathByAppendingComponent(pathBase, IDBFactoryBackendImpl::databaseFileName(name, securityOrigin)); } OwnPtr<SQLiteDatabase> sqliteDatabase = adoptPtr(new SQLiteDatabase()); if (!sqliteDatabase->open(path)) { // FIXME: Is there any other thing we could possibly do to recover at this point? If so, do it rather than just erroring out. LOG_ERROR("Failed to open database file %s for IndexedDB", path.utf8().data()); return 0; } sqliteDatabase->setMaximumSize(maximumSize); return sqliteDatabase.release(); }
bool makeAllDirectories(const String& path) { PlatformRefPtr<IFileMgr> fileMgr = createRefPtrInstance<IFileMgr>(AEECLSID_FILEMGR); return makeAllDirectories(fileMgr.get(), canonicalPath(path)); }
bool SQLiteFileSystem::ensureDatabaseDirectoryExists(const String& path) { if (path.isEmpty()) return false; return makeAllDirectories(path); }