NSFC_PR_GetFileInfo(const char *filename, PRFileInfo64 *finfo) { PRStatus rv; #ifdef ESTALE // Retry PR_GetFileInfo64() up to NSFC_ESTALE_RETRIES times if it returns // ESTALE. Bug 545152 int retries = NSFC_ESTALE_RETRIES; do { rv = PR_GetFileInfo64(filename, finfo); } while (rv == PR_FAILURE && PR_GetOSError() == ESTALE && retries--); #else rv = PR_GetFileInfo64(filename, finfo); #endif // Reject requests for "/index.html/" if (rv == PR_SUCCESS && finfo->type == PR_FILE_FILE) { int len = strlen(filename); if (len > 0) { #ifdef XP_WIN32 if (filename[len - 1] == '/' || filename[len - 1] == '\\') #else if (filename[len - 1] == '/') #endif { PR_SetError(PR_NOT_DIRECTORY_ERROR, 0); rv = PR_FAILURE; } } } return rv; }
void db_put_dn(char *data_dn) { int ret; char *db_path = DATABASE; char *db_path_bak = DATABASE_BACK; PRFileInfo64 info; PRFileDesc *prfd; PRInt32 data_sz; char *data_dnp = NULL; if(db_lock == NULL){ db_lock = PR_NewLock(); } PR_Lock(db_lock); /* if db_path is a directory, rename it */ ret = PR_GetFileInfo64(db_path, &info); if (PR_SUCCESS == ret) { if (PR_FILE_DIRECTORY == info.type) { /* directory */ ret = PR_GetFileInfo64(db_path_bak, &info); if (PR_SUCCESS == ret) { if (PR_FILE_DIRECTORY != info.type) { /* not a directory */ PR_Delete(db_path_bak); } } PR_Rename(db_path, db_path_bak); } } /* open a file */ if ((prfd = PR_Open(db_path, PR_RDWR | PR_CREATE_FILE | PR_APPEND, 0600)) == NULL ) { slapi_log_error(SLAPI_LOG_FATAL, DB_PLUGIN_NAME, "db: Could not open file \"%s\" for read/write; %d (%s)\n", db_path, PR_GetError(), slapd_pr_strerror(PR_GetError())); return; } data_dnp = slapi_ch_smprintf("%s\n", data_dn); data_sz = (PRInt32)strlen(data_dnp); ret = PR_Write(prfd, data_dnp, data_sz); if (ret == data_sz) { slapi_log_error(SLAPI_LOG_PLUGIN, DB_PLUGIN_NAME, "db: %s: key stored.\n", data_dn); ret = 0; } else { slapi_log_error(SLAPI_LOG_FATAL, DB_PLUGIN_NAME, "db: Failed to store key \"%s\"; %d (%s)\n", data_dn, PR_GetError(), slapd_pr_strerror(PR_GetError())); ret = 1; } if(ret) { slapi_log_error(SLAPI_LOG_FATAL, DB_PLUGIN_NAME, "db: Error detected in db_put_dn \n"); } slapi_ch_free_string(&data_dnp); PR_Close(prfd); PR_Unlock(db_lock); return; }
nsresult AutoMemMap::init(const char* filePath, int flags, int mode, PRFileMapProtect prot) { MOZ_ASSERT(!fd); MOZ_ASSERT(!fileMap); MOZ_ASSERT(!addr); if (PR_GetFileInfo64(filePath, &fileInfo) != PR_SUCCESS) return NS_ERROR_FILE_NOT_FOUND; // Check if the file is too big to memmap. if (fileInfo.size > int64_t(UINT32_MAX)) return NS_ERROR_INVALID_ARG; auto length = uint32_t(fileInfo.size); fd = PR_Open(filePath, flags, flags); if (!fd) return NS_ERROR_UNEXPECTED; fileMap = PR_CreateFileMap(fd, fileInfo.size, prot); if (!fileMap) return NS_ERROR_UNEXPECTED; addr = PR_MemMap(fileMap, 0, length); if (!addr) return NS_ERROR_UNEXPECTED; return NS_OK; }
//------------------------------------------------------------------------- // // Show - Display the file dialog // //------------------------------------------------------------------------- NS_IMETHODIMP nsFilePicker::Show(PRInt16 *retval) { NS_ENSURE_ARG_POINTER(retval); PRBool result = PR_FALSE; nsCAutoString fileBuffer; char *converted = ConvertToFileSystemCharset(mDefault); if (nsnull == converted) { LossyCopyUTF16toASCII(mDefault, fileBuffer); } else { fileBuffer.Assign(converted); nsMemory::Free( converted ); } char *title = ConvertToFileSystemCharset(mTitle); if (nsnull == title) title = ToNewCString(mTitle); nsCAutoString initialDir; if (mDisplayDirectory) mDisplayDirectory->GetNativePath(initialDir); // If no display directory, re-use the last one. if(initialDir.IsEmpty()) initialDir = mLastUsedDirectory; mFile.Truncate(); FILEDLG filedlg; memset(&filedlg, 0, sizeof(FILEDLG)); filedlg.cbSize = sizeof(FILEDLG); filedlg.pszTitle = title; if (mMode == modeGetFolder) { PL_strncat(filedlg.szFullFile, initialDir.get(), MAX_PATH); PL_strncat(filedlg.szFullFile, "\\", 1); PL_strncat(filedlg.szFullFile, "^", 1); filedlg.fl = FDS_OPEN_DIALOG | FDS_CENTER; filedlg.pfnDlgProc = DirDialogProc; DosError(FERR_DISABLEHARDERR); WinFileDlg(HWND_DESKTOP, mWnd, &filedlg); DosError(FERR_ENABLEHARDERR); char* tempptr = strstr(filedlg.szFullFile, "^"); if (tempptr) *tempptr = '\0'; if (filedlg.lReturn == DID_OK) { result = PR_TRUE; if (!mDisplayDirectory) mDisplayDirectory = do_CreateInstance("@mozilla.org/file/local;1"); if (mDisplayDirectory) mDisplayDirectory->InitWithNativePath(nsDependentCString(filedlg.szFullFile)); mFile.Assign(filedlg.szFullFile); } } else { PL_strncpy(filedlg.szFullFile, initialDir.get(), MAX_PATH); PL_strncat(filedlg.szFullFile, "\\", 1); PL_strncat(filedlg.szFullFile, fileBuffer.get(), MAX_PATH); filedlg.fl = FDS_CENTER; if (mMode == modeSave) { filedlg.fl |= FDS_SAVEAS_DIALOG | FDS_ENABLEFILELB; } else if (mMode == modeOpenMultiple) { filedlg.fl |= FDS_MULTIPLESEL | FDS_OPEN_DIALOG; } else { filedlg.fl |= FDS_OPEN_DIALOG; } PMYDATA pmydata; pmydata = (PMYDATA)calloc(1, sizeof(MYDATA)); filedlg.ulUser = (ULONG)pmydata; filedlg.pfnDlgProc = FileDialogProc; PRUint32 i; PSZ *apszTypeList; apszTypeList = (PSZ *)malloc(mTitles.Length()*sizeof(PSZ)+1); for (i = 0; i < mTitles.Length(); i++) { const nsString& typeWide = mTitles[i]; nsAutoCharBuffer buffer; PRInt32 bufLength; WideCharToMultiByte(0, typeWide.get(), typeWide.Length(), buffer, bufLength); apszTypeList[i] = ToNewCString(nsDependentCString(buffer.Elements())); } apszTypeList[i] = 0; filedlg.papszITypeList = (PAPSZ)apszTypeList; PSZ *apszFilterList; apszFilterList = (PSZ *)malloc(mFilters.Length()*sizeof(PSZ)+1); for (i = 0; i < mFilters.Length(); i++) { const nsString& filterWide = mFilters[i]; apszFilterList[i] = ToNewCString(filterWide); } apszFilterList[i] = 0; pmydata->papszIFilterList = (PAPSZ)apszFilterList; pmydata->ulCurExt = mSelectedType; PRBool fileExists; do { DosError(FERR_DISABLEHARDERR); WinFileDlg(HWND_DESKTOP, mWnd, &filedlg); DosError(FERR_ENABLEHARDERR); if ((filedlg.lReturn == DID_OK) && (mMode == modeSave)) { PRFileInfo64 fileinfo64; PRStatus status = PR_GetFileInfo64(filedlg.szFullFile, &fileinfo64); if (status == PR_SUCCESS) { fileExists = PR_TRUE; } else { fileExists = PR_FALSE; } if (fileExists) { if (!gpszFDSaveCaption) { HMODULE hmod; char LoadError[CCHMAXPATH]; char loadedString[256]; int length; DosLoadModule(LoadError, CCHMAXPATH, "PMSDMRI", &hmod); length = WinLoadString((HAB)0, hmod, 1110, 256, loadedString); gpszFDSaveCaption = (char*)malloc(length+1); strcpy(gpszFDSaveCaption, loadedString); length = WinLoadString((HAB)0, hmod, 1135, 256, loadedString); gpszFDFileExists = (char*)malloc(length+1); strcpy(gpszFDFileExists, loadedString); length = WinLoadString((HAB)0, hmod, 1136, 256, loadedString); gpszFDFileReadOnly = (char*)malloc(length+1); strcpy(gpszFDFileReadOnly, loadedString); int i; for (i=0;i<256 && gpszFDFileExists[i];i++ ) { if (gpszFDFileExists[i] == '%') { gpszFDFileExists[i+1] = 's'; break; } } for (i=0;i<256 && gpszFDFileReadOnly[i];i++ ) { if (gpszFDFileReadOnly[i] == '%') { gpszFDFileReadOnly[i+1] = 's'; break; } } DosFreeModule(hmod); } char pszFullText[256+CCHMAXPATH]; FILESTATUS3 fsts3; ULONG ulResponse; DosQueryPathInfo( filedlg.szFullFile, FIL_STANDARD, &fsts3, sizeof(FILESTATUS3)); if (fsts3.attrFile & FILE_READONLY) { sprintf(pszFullText, gpszFDFileReadOnly, filedlg.szFullFile); ulResponse = WinMessageBox(HWND_DESKTOP, mWnd, pszFullText, gpszFDSaveCaption, 0, MB_OK | MB_MOVEABLE | MB_WARNING); } else { sprintf(pszFullText, gpszFDFileExists, filedlg.szFullFile); ulResponse = WinMessageBox(HWND_DESKTOP, mWnd, pszFullText, gpszFDSaveCaption, 0, MB_YESNO | MB_MOVEABLE | MB_WARNING); } if (ulResponse == MBID_YES) { fileExists = PR_FALSE; } } } } while (mMode == modeSave && fileExists && filedlg.lReturn == DID_OK); if (filedlg.lReturn == DID_OK) { result = PR_TRUE; if (mMode == modeOpenMultiple) { nsresult rv; if (filedlg.papszFQFilename) { for (ULONG i=0;i<filedlg.ulFQFCount;i++) { nsCOMPtr<nsILocalFile> file = do_CreateInstance("@mozilla.org/file/local;1", &rv); NS_ENSURE_SUCCESS(rv,rv); rv = file->InitWithNativePath(nsDependentCString(*(filedlg.papszFQFilename)[i])); NS_ENSURE_SUCCESS(rv,rv); rv = mFiles.AppendObject(file); NS_ENSURE_SUCCESS(rv,rv); } WinFreeFileDlgList(filedlg.papszFQFilename); } else { nsCOMPtr<nsILocalFile> file = do_CreateInstance("@mozilla.org/file/local;1", &rv); NS_ENSURE_SUCCESS(rv,rv); rv = file->InitWithNativePath(nsDependentCString(filedlg.szFullFile)); NS_ENSURE_SUCCESS(rv,rv); rv = mFiles.AppendObject(file); NS_ENSURE_SUCCESS(rv,rv); } } else { mFile.Assign(filedlg.szFullFile); } mSelectedType = (PRInt16)pmydata->ulCurExt; } for (i = 0; i < mTitles.Length(); i++) { nsMemory::Free(*(filedlg.papszITypeList[i])); } free(filedlg.papszITypeList); for (i = 0; i < mFilters.Length(); i++) { nsMemory::Free(*(pmydata->papszIFilterList[i])); } free(pmydata->papszIFilterList); free(pmydata); } if (title) nsMemory::Free( title ); if (result) { PRInt16 returnOKorReplace = returnOK; nsresult rv; // Remember last used directory. nsCOMPtr<nsILocalFile> file(do_CreateInstance("@mozilla.org/file/local;1", &rv)); NS_ENSURE_SUCCESS(rv, rv); file->InitWithNativePath(mFile); nsCOMPtr<nsIFile> dir; if (NS_SUCCEEDED(file->GetParent(getter_AddRefs(dir)))) { nsCOMPtr<nsILocalFile> localDir(do_QueryInterface(dir)); if (localDir) { nsCAutoString newDir; localDir->GetNativePath(newDir); if(!newDir.IsEmpty()) PL_strncpyz(mLastUsedDirectory, newDir.get(), MAX_PATH+1); // Update mDisplayDirectory with this directory, also. // Some callers rely on this. if (!mDisplayDirectory) mDisplayDirectory = do_CreateInstance("@mozilla.org/file/local;1"); if (mDisplayDirectory) mDisplayDirectory->InitWithNativePath( nsDependentCString(mLastUsedDirectory) ); } } if (mMode == modeSave) { // Windows does not return resultReplace, // we must check if file already exists PRBool exists = PR_FALSE; file->Exists(&exists); if (exists) returnOKorReplace = returnReplace; } *retval = returnOKorReplace; } else { *retval = returnCancel; } return NS_OK; }
nsresult nsProfileCollector::LogInstall(nsIMetricsEventItem *profile) { nsCOMPtr<nsIWritablePropertyBag2> properties; nsMetricsUtils::NewPropertyBag(getter_AddRefs(properties)); NS_ENSURE_STATE(properties); nsCOMPtr<nsIXULAppInfo> appInfo = do_GetService(XULAPPINFO_SERVICE_CONTRACTID); NS_ENSURE_STATE(appInfo); nsCString buildID; appInfo->GetAppBuildID(buildID); properties->SetPropertyAsACString(NS_LITERAL_STRING("buildid"), buildID); MS_LOG(("Logged install buildid=%s", buildID.get())); nsCOMPtr<nsIExtensionManager> em = do_GetService("@mozilla.org/extensions/manager;1"); NS_ENSURE_STATE(em); nsCOMPtr<nsIUpdateItem> item; nsresult rv = em->GetItemForID(NS_LITERAL_STRING("*****@*****.**"), getter_AddRefs(item)); NS_ENSURE_SUCCESS(rv, rv); // get the metrics extension version nsAutoString extversion; rv = item->GetVersion(extversion); NS_ENSURE_SUCCESS(rv, rv); properties->SetPropertyAsAString(NS_LITERAL_STRING("extversion"), extversion); MS_LOG(("Logged install extversion=%s", NS_ConvertUTF16toUTF8(extversion).get())); // get the application version nsCString appversion; appInfo->GetVersion(appversion); properties->SetPropertyAsACString(NS_LITERAL_STRING("appversion"), appversion); MS_LOG(("Logged install appversion=%s", appversion.get())); // get the application locale nsCOMPtr<nsILocaleService> ls = do_GetService(NS_LOCALESERVICE_CONTRACTID); NS_ENSURE_STATE(ls); nsCOMPtr<nsILocale> locale(nsnull); rv = ls->GetApplicationLocale(getter_AddRefs(locale)); NS_ENSURE_SUCCESS(rv, rv); nsAutoString l; rv = locale->GetCategory(NS_LITERAL_STRING("NSILOCALE_CTYPE"), l); NS_ENSURE_SUCCESS(rv, rv); properties->SetPropertyAsAString(NS_LITERAL_STRING("locale"), l); MS_LOG(("Logged install locale=%s", NS_ConvertUTF16toUTF8(l).get())); // The file defaults/pref/channel-prefs.js is exlucded from any // security update, so we can use its creation time as an indicator // of when this installation was performed. nsCOMPtr<nsIFile> prefsDirectory; NS_GetSpecialDirectory(NS_APP_PREF_DEFAULTS_50_DIR, getter_AddRefs(prefsDirectory)); nsCOMPtr<nsILocalFile> channelPrefs = do_QueryInterface(prefsDirectory); NS_ENSURE_STATE(channelPrefs); rv = channelPrefs->Append(NS_LITERAL_STRING("channel-prefs.js")); NS_ENSURE_SUCCESS(rv, rv); nsCString nativePath; channelPrefs->GetNativePath(nativePath); PRFileInfo64 fileInfo; if (PR_GetFileInfo64(nativePath.get(), &fileInfo) == PR_SUCCESS) { // Convert the time to seconds since the epoch PRInt64 installTime = fileInfo.creationTime / PR_USEC_PER_SEC; static const int kSecondsPerDay = 60 * 60 * 24; // Round down to the nearest full day installTime = ((installTime / kSecondsPerDay) * kSecondsPerDay); properties->SetPropertyAsInt64(NS_LITERAL_STRING("installdate"), installTime); MS_LOG(("Logged install installdate=%lld", installTime)); } // TODO: log default= based on default-browser selection properties->SetPropertyAsBool(NS_LITERAL_STRING("default"), PR_TRUE); rv = nsMetricsUtils::AddChildItem(profile, NS_LITERAL_STRING("install"), properties); NS_ENSURE_SUCCESS(rv, rv); return NS_OK; }
PRStatus RCFileIO::FileInfo(const char *name, RCFileInfo* info) { return PR_GetFileInfo64(name, &info->info); }