bool GameInfo::DeleteGame() { switch (fileType) { case FILETYPE_PSP_ISO: case FILETYPE_PSP_ISO_NP: { // Just delete the one file (TODO: handle two-disk games as well somehow). const char *fileToRemove = fileInfo.fullName.c_str(); deleteFile(fileToRemove); auto i = std::find(g_Config.recentIsos.begin(), g_Config.recentIsos.end(), fileToRemove); if (i != g_Config.recentIsos.end()) { g_Config.recentIsos.erase(i); } return true; } case FILETYPE_PSP_PBP_DIRECTORY: { // TODO: This could be handled by Core/Util/GameManager too somehow. const char *directoryToRemove = fileInfo.fullName.c_str(); INFO_LOG(HLE, "Deleting %s", directoryToRemove); if (!File::DeleteDirRecursively(directoryToRemove)) { ERROR_LOG(HLE, "Failed to delete file"); return false; } g_Config.CleanRecent(); return true; } default: return false; } }
int deleteDir(char *dirname) { char __aligned buffer[2048]; struct ExAllControl *ec; int moreFromExAll, success = TRUE; BPTR lock; if(!(lock = Lock(dirname, ACCESS_READ))) { return 1; } printf("Deleting all files in directory %s\n", dirname); ec = (struct ExAllControl *) AllocDosObject(DOS_EXALLCONTROL, NULL); ec->eac_LastKey=0L; ec->eac_MatchString=NULL; ec->eac_MatchFunc=NULL; do { moreFromExAll = ExAll(lock, (struct ExAllData *)buffer, 2048, ED_TYPE, ec); if(!handleExAllResult(ec, (struct ExAllData *) buffer, dirname)) { success = FALSE; break; } } while(moreFromExAll); UnLock(lock); FreeDosObject(DOS_EXALLCONTROL,ec); if(success) { success = deleteFile(dirname); } return success; }
bool FileLogLocation::OpenFile() { _canLog = false; _fileStream.close(); _fileIsClosed = true; double ts; GETCLOCKS(ts); ts = (ts / CLOCKS_PER_SECOND)*1000; string temp = format("%s.%"PRIu64".%"PRIu64, STR(_fileName), (uint64_t) getpid(), (uint64_t) ts); ios_base::openmode openMode = ios_base::out | ios_base::binary | ios_base::trunc; _fileStream.open(STR(temp), openMode); if (_fileStream.fail()) { return false; } _fileStream << "PID: " << getpid() << "; TIMESTAMP: " << time(NULL) << endl; if (_fileHistorySize > 0) { ADD_VECTOR_END(_history, temp); while (_history.size() > _fileHistorySize) { deleteFile(_history[0]); _history.erase(_history.begin()); } } _currentLength = 0; _canLog = true; _fileIsClosed = false; return true; }
// CAPP_WEB_SAVE_IMAGE_TO_FILE int CachedImage::saveToFile(const String& filePath) { RefPtr<SharedBuffer> imageBuffer = m_data.get(); if (NULL == imageBuffer || 0 == imageBuffer->size()) { return 0; } PlatformFileHandle fileHandle = open(filePath.utf8().data(), O_WRONLY | O_CREAT | O_TRUNC /*| O_EXCL*/, S_IRUSR | S_IWUSR | S_IROTH); if ( -1 == fileHandle ) { return -1; } const char* segment = NULL; unsigned pos = 0; unsigned writtenBytes = 0; while (unsigned length = imageBuffer->getSomeData(segment, pos)) { writtenBytes = writeToFile(fileHandle, segment, length); if (writtenBytes < 0 || writtenBytes < length) { closeFile(fileHandle); deleteFile(filePath); return -1; } pos += length; } closeFile(fileHandle); return 1; }
InboundNamedPipeCarrier *InboundNamedPipeCarrier::Create(string path, uint16_t mode) { if (mkfifo(STR(path), mode) != 0) { int err = errno; FATAL("Unable to create named pipe %s with mode %u: %s (%d)", STR(path), (uint32_t) mode, strerror(err), err); return NULL; } int32_t fd = open(STR(path), O_RDONLY | O_NONBLOCK); if (fd < 0) { int err = errno; FATAL("Unable to open named pipe %s:%s (%d)", STR(path), strerror(err), err); deleteFile(path); return NULL; } InboundNamedPipeCarrier *pResult = new InboundNamedPipeCarrier(fd, path); if (!IOHandlerManager::EnableReadData(pResult)) { FATAL("Unable to enable read event on the named pipe"); delete pResult; return NULL; } return pResult; }
void createNewSegment(const char *directory, const char *segment, unsigned long size, int extendSegment) { char* segInfoFileName = combinePaths(directory, SEGINFO_FILE); FILE* fd = fopen(segInfoFileName, "r"); if (fd) { char line[1024]; char *tempFileName = combinePaths(directory, "lrvmSEGINFO""tmp"); FILE* tempFIleFd = fopen(tempFileName, "w"); while (readLineFromFile(fd,line,sizeof(line))) { if (startsWith(SEGNAMESTR, line) && !strcmp(line + strlen(SEGNAMESTR), segment)) { readLineFromFile(fd,line,sizeof(line)); fprintf(tempFIleFd, "%s%s\n", SEGNAMESTR, segment); sprintf(line, "%s%lu", SEGSIZESTR, size); fprintf(tempFIleFd, "%s\n", line); } else { fprintf(tempFIleFd, "%s\n", line); } } if (!extendSegment) { fprintf(tempFIleFd, "%s%s\n", SEGNAMESTR, segment); sprintf(line, "%s%lu", SEGSIZESTR, size); fprintf(tempFIleFd, "%s\n", line); } fclose(tempFIleFd); fclose(fd); copyFile(tempFileName, segInfoFileName); deleteFile(tempFileName); free(tempFileName); } else { fprintf(stderr, "STDERR:unable to read seg info file\n"); abort(); } free(segInfoFileName); struct stat fileInfo; char* targetSegmentFile = combinePaths(directory, segment); if (extendSegment && !stat(targetSegmentFile, &fileInfo)) { char tempSegFileName[1024]; sprintf(tempSegFileName, "%s/%s%s%s", directory, SEGINFO_FILE, segment, "tmp"); copyExtended(targetSegmentFile, tempSegFileName, size); copyFile(tempSegFileName, targetSegmentFile); deleteFile(tempSegFileName); } else { createNullFile(targetSegmentFile, size); } free(targetSegmentFile); }
void LocalStorageDatabaseTracker::deleteAllDatabases() { m_origins.clear(); openTrackerDatabase(SkipIfNonExistent); if (!m_database.isOpen()) return; SQLiteStatement statement(m_database, "SELECT origin, path FROM Origins"); if (statement.prepare() != SQLITE_OK) { LOG_ERROR("Failed to prepare statement."); return; } int result; while ((result = statement.step()) == SQLITE_ROW) { deleteFile(statement.getColumnText(1)); // FIXME: Call out to the client. } if (result != SQLITE_DONE) LOG_ERROR("Failed to read in all origins from the database."); if (m_database.isOpen()) m_database.close(); if (!deleteFile(trackerDatabasePath())) { // In the case where it is not possible to delete the database file (e.g some other program // like a virus scanner is accessing it), make sure to remove all entries. openTrackerDatabase(SkipIfNonExistent); if (!m_database.isOpen()) return; SQLiteStatement deleteStatement(m_database, "DELETE FROM Origins"); if (deleteStatement.prepare() != SQLITE_OK) { LOG_ERROR("Unable to prepare deletion of all origins"); return; } if (!deleteStatement.executeCommand()) { LOG_ERROR("Unable to execute deletion of all origins"); return; } } deleteEmptyDirectory(m_localStorageDirectory); }
/* main test functions */ int create(void) { char buf[4096]; char *s; int i; int ret = 1; char *spec; if ( ret && createDir(testDir) ) ret = 0; if ( totalSize < maxSize ) { maxSize = totalSize; } int nb = maxSize; spec = specToName(0, nb, csv); STARTTIME(); for(i=0;i < nb &&createFileBefore;i++) { snprintf(buf,sizeof(buf), "%s/f_%d",testDir,i); int fd = open(buf, O_WRONLY | O_CREAT | O_TRUNC, 0666); if ( fd > 0 ) { close(fd); } else { ret = 0; break; } } ENDTIME(); SETDT(); double createPerSecond = nb*1000000.0/dt; fprintf(stdout,"Create %-18s time %8.3f sec %8.0f F/s\n", spec, (double)dt/1000000, createPerSecond ); STARTTIME(); for(i=0;i < nb; i++) { snprintf(buf,sizeof(buf),"%s/f_%d",testDir,i); deleteFile(buf); } ENDTIME(); SETDT(); createPerSecond = nb*1000000.0/dt; fprintf(stdout,"Delete %-18s time %8.3f sec %8.0f F/s\n", spec, (double)dt/1000000, createPerSecond ); deleteTestDir(1); return ret; }
void NetscapePluginStream::stop(NPReason reason) { // The stream was stopped before it got a chance to start. This can happen if a stream is cancelled by // WebKit before it received a response. if (!m_isStarted) { ASSERT(reason != NPRES_DONE); notifyAndDestroyStream(reason); return; } if (reason == NPRES_DONE && m_deliveryData && !m_deliveryData->isEmpty()) { // There is still data left that the plug-in hasn't been able to consume yet. ASSERT(m_deliveryDataTimer.isActive()); // Set m_stopStreamWhenDoneDelivering to true so that the next time the delivery timer fires // and calls deliverDataToPlugin the stream will be closed if all the remaining data was // successfully delivered. m_stopStreamWhenDoneDelivering = true; return; } m_deliveryData = nullptr; m_deliveryDataTimer.stop(); if (m_transferMode == NP_ASFILE || m_transferMode == NP_ASFILEONLY) { if (reason == NPRES_DONE) { // Ensure that the file is created. deliverDataToFile(0, 0); if (m_fileHandle != invalidPlatformFileHandle) closeFile(m_fileHandle); ASSERT(!m_filePath.isNull()); m_plugin->NPP_StreamAsFile(&m_npStream, m_filePath.utf8().data()); } else { // Just close the file. if (m_fileHandle != invalidPlatformFileHandle) closeFile(m_fileHandle); } // Delete the file after calling NPP_StreamAsFile(), instead of in the destructor. It should be OK // to delete the file here -- NPP_StreamAsFile() is always called immediately before NPP_DestroyStream() // (the stream destruction function), so there can be no expectation that a plugin will read the stream // file asynchronously after NPP_StreamAsFile() is called. deleteFile(m_filePath); m_filePath = String(); // NPP_StreamAsFile could call NPN_DestroyStream and destroy the stream. if (!m_isStarted) return; } // Set m_isStarted to false before calling NPP_DestroyStream in case NPP_DestroyStream calls NPN_DestroyStream. m_isStarted = false; m_plugin->NPP_DestroyStream(&m_npStream, reason); notifyAndDestroyStream(reason); }
void iurlstream::close() { std::ifstream::close(); if (!m_tempFilePath.empty() && fileExists(m_tempFilePath)) { deleteFile(m_tempFilePath); } m_tempFilePath = ""; m_lastError = 0; }
void NetworkDataTaskBlob::cleanDownloadFiles() { if (m_downloadFile != invalidPlatformFileHandle) { closeFile(m_downloadFile); m_downloadFile = invalidPlatformFileHandle; } deleteFile(m_pendingDownloadLocation); }
int main() { readFile( fileToRead ); TMyApp myApp; myApp.run(); deleteFile(); return 0; }
Field::~Field() { for(int i=0 ; i<files.size() ; ++i) { deleteFile((FileType)i); } deleteCharaFile(); }
void OriginLock::deleteLockFile(String originPath) { UNUSED_PARAM(originPath); #if USE(FILE_LOCK) String lockFileName = OriginLock::lockFileNameForPath(originPath); deleteFile(lockFileName); #endif }
void endError(){ // clean up if(tempClausesFileGlobal != NULL){ fclose(tempClausesFileGlobal); deleteFile(TEMP_CLAUSE_FILE); } exit(0); }
int main() { int choice; char ans = 'y'; char fname[SIZE]; struct linknode *hashTable[TABLESIZE]; initializeHashTable(hashTable); while(ans == 'y') { printf("\n1. Create file\n"); printf("2. Delete File\n"); printf("3. Search File\n"); printf("4. Display Table\n"); printf("5. Exit\n"); printf("6. Write to disk\n"); printf("7. Read from disk\n"); printf("\nEnter choice: "); scanf("%d", &choice); switch(choice) { case 1: printf("Enter file name: "); scanf("%s", fname); insertFile(fname, hashTable); break; case 2: printf("Enter file name: "); scanf("%s", fname); deleteFile(fname, hashTable); break; case 3: printf("Enter file name: "); scanf("%s", fname); searchFile(fname, hashTable); break; case 4: displayTable(hashTable); break; case 5: exit(0); case 6: writeToDisk(hashTable); break; case 7: readFromDisk(hashTable); break; } } return (0); }
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); }
void writeFile(char * name, char * buffer, int numberOfSectors){ char dir[512]; char map[512]; char tmpSect[512]; int dirNum = 0; int i = 0; int sectNum = 0; int k = 0; int iBuf = 0; readSector(dir, 2); readSector(map, 1); dirNum = findFreeDir(dir); if(dirNum >= 16){ return; } // Writing the name in directory while(name[i] != 0x0){ dir[dirNum*32+i] = name[i]; i++; } // Writing data and map for(i = 0; i <= numberOfSectors; i++){ // Locating free sector while(map[sectNum] != 0x0){ sectNum++; } if(i >= 16){ deleteFile(name); return; } printString(name); // Writing to map and directory map[sectNum] = 0xFF; writeSector(map, 0); dir[dirNum*32+6+i] = sectNum; // Writing the sector for(k = 0; k < 512; k++){ tmpSect[k] = buffer[iBuf]; iBuf++; } writeSector(tmpSect, sectNum); } // Filling the rest of the dir entry with 0x00 while(i<16){ dir[dirNum*32+6+i] = 0x0; i++; } writeSector(map, 1); writeSector(dir, 2); }
/*! * Rename a file from oldName to newName. If the file newName already exists * it will be deleted. * \param oldName is the old name of the file * \param newName is the new name of the file */ void ProtocolFile::renameFile(const QString& oldName, const QString& newName) { // Make sure the new file does not exist deleteFile(newName); // Now make the old name become the new name makeFileWritable(oldName); QFile::rename(oldName, newName); }// ProtocolFile::renameFile
bool File::deleteRecursively() const { bool worked = true; if (isDirectory()) for (auto& f : findChildFiles (File::findFilesAndDirectories, false)) worked = f.deleteRecursively() && worked; return deleteFile() && worked; }
void FileManager::moveFileToFolder(QString originPath, QString originName,QString newPath,QString newName) { if(QString::compare(originPath,newPath)==0 && QString::compare(originName,newName)==0) return; copyFileToFolder(originPath,originName, newPath, newName); historyFromPath.push(originPath); historyFromName.push(originName); historyToPath.push(newPath); historyToName.push(newName); historyType.push_back("folder"); deleteFile(originPath + "/" + originName); }
bool FileSystem::sendFileByRange(int connFd, Message_fs msg ) { bool deleteMyCopy = ( (msg.type == MSG_PULL_MV) ? true : false ); logFile<<"sendFileByRange: "<<msg.minKey<<" to "<<msg.maxKey<<endl; std::vector<std::string> toremove; filesLock.lock(); size_t count = 0; for( auto &file : files ){ if( inRange(file.key, msg.minKey, msg.maxKey) ) count++; } msg.size = count; write(connFd, &msg, sizeof(Message_fs)); for( auto &file : files ) { if( inRange(file.key, msg.minKey, msg.maxKey) ) { memset(msg.filename, '\0', 200); file.filename.copy(msg.filename, file.filename.length() ); // cout<<"sendFileByRange: "<<file.filename<<" "<<msg.filename<<endl; logFile<<"sendFileByRange: "<<file.filename<<" rm:"<<deleteMyCopy<<endl; char * buffer; msg.size = readFile(file.filename, &buffer); write(connFd, &msg, sizeof(Message_fs)); splitWrite(connFd, buffer, msg.size); delete buffer; if(deleteMyCopy) { //files.remove( file ); //maintain file list toremove.push_back(file.filename); } } } for (int i = 0; i < toremove.size(); ++i) { if ( deleteFile( toremove.at(i) ) ) { logFile << toremove.at(i) << "deleted" << std::endl; } files.remove(toremove.at(i)); } filesLock.unlock(); return true; }
//////////////////////////////////////////////////////////////////////////////////// /// /// \brief Delete's an array of files /// /// \param fnames An array of files to delete /// /// \result Numbe of files sucessfully deleted /// //////////////////////////////////////////////////////////////////////////////////// int FileIO::deleteFiles(const Array<String> &fnames) { int result = 0; for (unsigned int i = 0; i < fnames.size(); i++) { result += deleteFile(fnames[i]); } return result; }
void NetworkDataTaskBlob::setPendingDownloadLocation(const String& filename, const SandboxExtension::Handle& sandboxExtensionHandle, bool allowOverwrite) { NetworkDataTask::setPendingDownloadLocation(filename, sandboxExtensionHandle, allowOverwrite); ASSERT(!m_sandboxExtension); m_sandboxExtension = SandboxExtension::create(sandboxExtensionHandle); if (m_sandboxExtension) m_sandboxExtension->consume(); if (allowOverwrite && fileExists(m_pendingDownloadLocation)) deleteFile(m_pendingDownloadLocation); }
void CurlDownload::didFail() { MutexLocker locker(m_mutex); closeFile(); if (m_deletesFileUponFailure) deleteFile(m_tempPath); if (m_listener) m_listener->didFail(); }
bool VUtils::deleteFile(const VOrphanFile *p_file, const QString &p_path, bool p_skipRecycleBin) { if (p_skipRecycleBin) { QFile file(p_path); return file.remove(); } else { // Move it to the recycle bin folder. return deleteFile(p_file->fetchRecycleBinFolderPath(), p_path); } }
bool VUtils::deleteFile(const VNotebook *p_notebook, const QString &p_path, bool p_skipRecycleBin) { if (p_skipRecycleBin) { QFile file(p_path); return file.remove(); } else { // Move it to the recycle bin folder. return deleteFile(p_notebook->getRecycleBinFolderPath(), p_path); } }
void IndexFileDeleter::decRef(const string& fileName) { RefCount* rc = getRefCount(fileName.c_str()); if (infoStream != NULL && VERBOSE_REF_COUNTS) { message(string(" DecRef \"") + fileName + "\": pre-decr count is " + Misc::toString((int32_t)rc->count)); } if (0 == rc->DecRef()) { // This file is no int32_t64_ter referenced by any past // commit point32_ts nor by the in-memory SegmentInfos: deleteFile(fileName.c_str()); refCounts.remove((char*)fileName.c_str()); } }
void *shmServerConstructor(void *arg) { //Create the key file for shm and sem keyfiles deleteFile(SHMKEYPATH); deleteFile(SEMKEYPATH); createEmptyFile(SHMKEYPATH); createEmptyFile(SEMKEYPATH); //initiator first shmServerInitiator(); //Create Clients' Check status shmServer.gsThreadID = pthread_create(&shmServer.gsThread, NULL, shmServerClientCheck, NULL); trace_printf("Thread shmServerClientCheck successfully"); pthread_join(shmServer.gsThread, NULL); trace_printf("Join threads Done"); shmServerDestructor(); return (void *) NULL; }
bool VUtils::deleteDirectory(const VNotebook *p_notebook, const QString &p_path, bool p_skipRecycleBin) { if (p_skipRecycleBin) { QDir dir(p_path); return dir.removeRecursively(); } else { // Move it to the recycle bin folder. return deleteFile(p_notebook->getRecycleBinFolderPath(), p_path); } }