CString CPathFinder::GetDriveLabel(BOOL bPCNameIfNetwork) { if (_sDriveLabel.IsEmpty() && !IsRelativePath()) { if ((bPCNameIfNetwork) && (!IsLocalPath())) _sDriveLabel = GetDir(0); else { CString sRoot; TCHAR szVolumeName[256]; szVolumeName[0] = '\0'; if (IsLocalPath()) { sRoot = _sDrive + CString(_T("\\")); } else if (GetDirCount() > 1) { sRoot.Format(_T("\\\\%s\\%s\\"), GetDir(0), GetDir(1)); } GetVolumeInformation(sRoot, szVolumeName, 255, NULL, NULL, NULL, NULL, 0); _sDriveLabel = szVolumeName; } } return _sDriveLabel; }
bool GetSubstName(int DriveType,const wchar_t *DeviceName, string &strTargetPath) { bool Ret=false; /* + Обработка в зависимости от Opt.SubstNameRule битовая маска: 0 - если установлен, то опрашивать сменные диски 1 - если установлен, то опрашивать все остальные */ bool DriveRemovable = (DriveType==DRIVE_REMOVABLE || DriveType==DRIVE_CDROM); if (DriveType==DRIVE_NOT_INIT || (((Opt.SubstNameRule & 1) || !DriveRemovable) && ((Opt.SubstNameRule & 2) || DriveRemovable))) { if (IsLocalPath(DeviceName)) { string Name; if (apiQueryDosDevice(DeviceName, Name)) { if (Name.Equal(0, L"\\??\\")) { strTargetPath=Name.SubStr(4); Ret=true; } } } } return Ret; }
// This function must be called whenever _arrDir array is needed, since this // method is the one which parses _strDir and fill _arrDir void CPath::FillDirArray() { if (_strDir.IsEmpty() || (_arrDir.GetSize() > 0)) return; int nFrom, nTo; // nFrom: 0 - relative / 1 - local / 2 - network nFrom = IsLocalPath() ? 1 : (IsRelativePath() ? 0 : 2); while ((nTo = _strDir.Find('\\', nFrom)) != -1) { _arrDir.Add(_strDir.Mid(nFrom, nTo - nFrom)); nFrom = nTo + 1; } }
/* Return physical size of directory contents, or 0 if dir doesn't exist */ int64 db_dir_size(const char *path) { int64 dirsize = 0; struct dirent *direntry; char filename[MAXPGPATH]; /* Deal with remote shared storage */ if (!IsLocalPath(path)) { dirsize += HdfsPathSize(path); } /* Local storage */ else { DIR *dirdesc = AllocateDir(path); if (!dirdesc) return 0; while ((direntry = ReadDir(dirdesc, path)) != NULL) { struct stat fst; if (strcmp(direntry->d_name, ".") == 0 || strcmp(direntry->d_name, "..") == 0) continue; snprintf(filename, MAXPGPATH, "%s/%s", path, direntry->d_name); if (stat(filename, &fst) < 0) { if (errno == ENOENT) continue; else ereport(ERROR, (errcode_for_file_access(), errmsg("could not stat file \"%s\": %m", filename))); } dirsize += fst.st_size; } FreeDir(dirdesc); } return dirsize; }
rc_t Initialize(unsigned int sra_sync, const char* xml_path, const char* cache_dir, const char* heart_beat_url, unsigned int xml_sync, const char* xml_root, uint32_t block_size) { rc_t rc = 0; KDirectory* dir = NULL; if( (rc = KDirectoryNativeDir(&dir)) == 0 ) { char buf[4096]; if( (rc = KDirectoryResolvePath(dir, true, buf, 4096, xml_root)) == 0 ) { /* replace /. at the end to just / */ if( strcmp(&buf[strlen(buf) - 2], "/.") == 0 ) { buf[strlen(buf) - 1] = '\0'; } /* add / to the end if missing */ if( buf[strlen(buf) - 1] != '/' ) { buf[strlen(buf) + 1] = '\0'; buf[strlen(buf)] = '/'; } if( (rc = StrDup(buf, &g_work_dir)) == 0 ) { DEBUG_MSG(8, ("Current directory set to '%s'\n", g_work_dir)); } } if ( rc == 0 ) { rc = RemoteCacheInitialize ( cache_dir ); if ( rc == 0 ) { RemoteCacheSetHttpBlockSize ( block_size ); if ( IsLocalPath ( xml_path ) ) { KDirectoryResolvePath(dir, true, buf, 4096, xml_path); rc = XML_Make(dir, g_work_dir, buf, heart_beat_url, xml_sync); } else { rc = XML_Make(dir, g_work_dir, xml_path, heart_beat_url, xml_sync); } } } ReleaseComplain(KDirectoryRelease, dir); } return rc; }