Example #1
0
bool CopyDir(std::string source, std::string target)
{
	if(PathExists(source)){
		if(!PathExists(target)){
			fs::CreateAllDirs(target);
		}
		bool retval = true;
		std::vector<DirListNode> content = fs::GetDirListing(source);

		for(unsigned int i=0; i < content.size(); i++){
			std::string sourcechild = source + DIR_DELIM + content[i].name;
			std::string targetchild = target + DIR_DELIM + content[i].name;
			if(content[i].dir){
				if(!fs::CopyDir(sourcechild, targetchild)){
					retval = false;
				}
			}
			else {
				if(!fs::CopyFileContents(sourcechild, targetchild)){
					retval = false;
				}
			}
		}
		return retval;
	}
	else {
		return false;
	}
}
Example #2
0
static int UpgradeNSIS(void)
{
	std::string installPath = GetNSISInstallPath();

	if (installPath.empty())
		return 0;

	std::string uninstallerPath = installPath + "\\uninstall.exe";

	if (!PathExists(uninstallerPath))
		return 0;

	std::string dataPath = GetIcingaDataPath();

	if (dataPath.empty())
		return 1;

	bool moveUserData = !PathExists(dataPath);

	/* perform open heart surgery on the user's data dirs - yay */
	if (moveUserData) {
		MkDir(dataPath.c_str());

		std::string oldNameEtc = installPath + "\\etc";
		std::string newNameEtc = dataPath + "\\etc";
		if (!CopyDirectory(oldNameEtc, newNameEtc))
			return 1;

		std::string oldNameVar = installPath + "\\var";
		std::string newNameVar = dataPath + "\\var";
		if (!CopyDirectory(oldNameVar, newNameVar))
			return 1;
	}

	ExecuteCommand(uninstallerPath, "/S _?=" + installPath);

	_unlink(uninstallerPath.c_str());

	if (moveUserData) {
		std::string oldNameEtc = installPath + "\\etc";
		if (!DeleteDirectory(oldNameEtc))
			return 1;

		std::string oldNameVar = installPath + "\\var";
		if (!DeleteDirectory(oldNameVar))
			return 1;

		_rmdir(installPath.c_str());
	}	

	return 0;
}
Example #3
0
	ContentHandle* ContentManager::ReadFile(std::wstring fileName)
	{
		auto p = MakePath(fileName);
		ContentHandle* ch = nullptr;
		if (m_dictHandles.TryGet(p, &ch))
		{
			if (ch && !ch->IsClosed())
				return ch;
		}
		else if (m_dictHandles.TryGet(fileName, &ch))
		{
			if (ch && !ch->IsClosed())
				return ch;
		}
		if (PathExists(p))
		{
			ch = new ContentHandle(p);
			if (ch->GetStream()->operator!())
				ch = nullptr;
			if (ch)
				RegisterHandle(p, ch);
		}
		else {
			Formats::SMC::smcs_info inf;
			if (m_pSystem->GetEntry(fileName, &inf))
			{
				ch = new ContentHandle(inf);
				if (ch)
					RegisterHandle(fileName, ch);
			}
		}
		return ch;
	}
Example #4
0
const OTString & OTPaths::AppDataFolder()
{
	if (m_strAppDataFolder.Exists()) return m_strAppDataFolder;  // already got it, just return it.

	OTString strHomeDataFolder(""), strAppDataFolder("");  // eg. /home/user/  (the folder that the OT appdata folder will be in.)

	if(!GetHomeFromSystem(strHomeDataFolder)) { OT_ASSERT(false); return m_strAppDataFolder; }

	// now lets change all the '\' into '/'
	// then check that the path /home/user indeed exists, and is a folder.

	FixPath(strHomeDataFolder,strHomeDataFolder,true);
	if(!PathExists(strHomeDataFolder)) OT_ASSERT(false);

	// ok, we have the HomeData Folder, lets append our OT folder to it.

	if(!AppendFolder(strAppDataFolder,strHomeDataFolder,OT_APPDATA_DIR)) OT_ASSERT(false);

	bool bFolderCreated;
	if(!BuildFolderPath(strAppDataFolder,bFolderCreated)) OT_ASSERT(false);

	m_strAppDataFolder = strAppDataFolder;  // all good lets set it.

	return m_strAppDataFolder;
}
// Creates directory specified by |path|. Creates parent directories if
// necessary. Returns 0 when successful.
int CreateDirectory(const std::string& path) {
  if (path.empty()) {
    return -1;
  }

  // Search |path| for /'s, and create all directories encountered.
  // Start at |pos| 1: assume filesystem root exists.
  typedef std::string::size_type size_type;
  for (size_type pos = 1; pos < path.length(); ++pos) {
    pos = path.find('/', pos);
    if (pos != std::string::npos) {
      // Copy from start through occurence of '/';
      const std::string directory = path.substr(0, pos);

      if (!PathExists(directory)) {
        // Make the directory with permissions allowing r/w for everyone.
        const mode_t mode_flags =
            S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
        if (mkdir(directory.c_str(), mode_flags)) {
          // Could not create directory.
          return -1;
        }
      }
    } else {
      break;
    }
  }
  return 0;
}
void TouchActivityFile() {
  // Generate the activity directory path for the current user, and create it
  // if it does not exist.
  const std::string activity_dir = GenerateActivityDirectoryPath();
  if (!PathIsDirectory(activity_dir)) {
    if (CreateDirectory(activity_dir)) {
      // Unable to create directory, abandon touch attempt.
      return;
    }
  }

  const std::string activity_file = activity_dir + kWebmBundleId;
  if (PathExists(activity_file)) {
    // There's nothing to do when the file exists. Keystone deletes it each
    // time it runs the activity check.
    return;
  }

  // Create |activity_file|.
  const int open_flags = O_WRONLY | O_CREAT | O_NONBLOCK | O_NOCTTY;
  const mode_t mode_flags =
      S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
  const int file_desc = open(activity_file.c_str(), open_flags, mode_flags);
  if (file_desc == -1) {
    // |open failed|, give up.
    return;
  }
  close(file_desc);
}
// Returns true when |path| exists and is a directory.
bool PathIsDirectory(const std::string& path) {
  if (PathExists(path)) {
    struct stat path_stat = {0};
    const int status = stat(path.c_str(), &path_stat);
    if (status == 0 && S_ISDIR(path_stat.st_mode)) {
      return true;
    }
  }
  return false;
}
Example #8
0
static void FindBIF(BIFEntry *entry)
{
	entry->cd = 0;
	entry->found = PathExists(entry, core->GamePath);
	if (entry->found) {
		return;
	}

	for (int i = 0; i < MAX_CD; i++) {
		if (PathExists(entry, core->CD[i]) ) {
			entry->found = true;
			entry->cd = i;
			return;
		}
	}

	printMessage("KEYImporter", "Cannot find %s...", WHITE, entry->name);
	printStatus( "ERROR", LIGHT_RED );
}
Example #9
0
	bool ContentManager::FileExists(std::wstring fileName)
	{
		auto p = MakePath(fileName);
		if (PathExists(p))
			return true;
		Formats::SMC::smcs_info inf;
		if (m_pSystem->GetEntry(fileName, &inf))
			return true;
		return false;
	}
Example #10
0
static void CopyConfigFile(const std::string& installDir, const std::string& sourceConfigPath, size_t skelPrefixLength)
{
	std::string relativeConfigPath = sourceConfigPath.substr(skelPrefixLength);

	std::string targetConfigPath = installDir + relativeConfigPath;

	if (!PathExists(targetConfigPath)) {
		MkDirP(DirName(targetConfigPath));
		CopyFile(sourceConfigPath, targetConfigPath);
	}
}
Example #11
0
static void FindBIFOnCD(BIFEntry *entry)
{
	if (file_exists(entry->path)) {
		entry->found = true;
		return;
	}

	core->WaitForDisc(entry->cd, entry->name);

	entry->found = PathExists(entry, core->CD[entry->cd-1]);
}
// Test that a new volume file isn't generated it already exists.
TEST_F(AudioVolumeHandlerTest, InitFilePresent) {
  KeyValueStore kv_store;
  kv_store.SetString("foo", "100");
  kv_store.Save(volume_file_path_);
  EXPECT_CALL(handler_, InitAPSAllStreams());
  handler_.Init(nullptr);
  EXPECT_TRUE(PathExists(volume_file_path_));
  std::string value;
  handler_.kv_store_->GetString("foo", &value);
  EXPECT_EQ(stoi(value), 100);
}
Example #13
0
static bool PathExists(BIFEntry *entry, const std::vector<std::string> &pathlist)
{
	size_t i;
	
	for(i=0;i<pathlist.size();i++) {
		if (PathExists(entry, pathlist[i].c_str() )) {
			return true;
		}
	}

	return false;
}
Example #14
0
BOOL install_util::CreateLnkPath(std::wstring wsSourceFilePath, std::wstring wsDestLnkPath, std::wstring wsArgument, std::wstring wsAppId)
{
  IShellLink *pisl = NULL;
  HRESULT hr = CoCreateInstance(CLSID_ShellLink,
    NULL,
    CLSCTX_INPROC_SERVER,
    IID_IShellLink,
    (void**)&pisl);
  if (FAILED(hr))
  {
    return FALSE;
  }

  pisl->SetPath(wsSourceFilePath.c_str());
  pisl->SetArguments(wsArgument.c_str());
  int nStart = wsSourceFilePath.find_last_of(_T("/\\")); 
  pisl->SetWorkingDirectory(wsSourceFilePath.substr(0,nStart).c_str());
  IPersistFile *plPF = NULL; 
  hr = pisl->QueryInterface(IID_IPersistFile, (void**)&plPF);
  bool shortcut_existed = false;
  if (SUCCEEDED(hr))
  {
    if (PathExists(wsDestLnkPath))
    {
      shortcut_existed = true;
      install_util::DeleteFile(wsDestLnkPath.c_str());
    }
	if (Win7OrLater() && !wsAppId.empty() && wsAppId.length() < 64)
	{
		IPropertyStore *piPS = NULL;
		if (SUCCEEDED(pisl->QueryInterface(IID_IPropertyStore, (void**)&piPS)))
		{
			PROPVARIANT property_value;
			if (SUCCEEDED(InitPropVariantFromString(wsAppId.c_str(), &property_value)))
			{
				if (piPS->SetValue(PKEY_AppUserModel_ID, property_value) == S_OK)
					piPS->Commit();
				PropVariantClear(&property_value);
			}
			piPS->Release();
		}
	}

    hr = plPF->Save(wsDestLnkPath.c_str(), TRUE);
    plPF->Release();
  }

  pisl->Release();
  SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL);

  return SUCCEEDED(hr);
}
Example #15
0
static void FindBIF(BIFEntry *entry)
{
	entry->cd = 0;
	entry->found = PathExists(entry, core->GamePath);
	if (entry->found) {
		return;
	}

	if (core->GameOnCD) {
		int mask = 1<<2;
		for(int cd = 1; cd<=MAX_CD; cd++) {
			if ((entry->BIFLocator & mask) != 0) {
				entry->cd = cd;
				break;
			}
			mask += mask;
		}

		if (!entry->cd) {
			printStatus( "ERROR", LIGHT_RED );
			print( "Cannot find %s... Resource unavailable.\n",
					entry->name );
			entry->found = false;
			return;
		}
		entry->found = PathExists(entry, core->CD[entry->cd-1]);
		return;
	}

	for (int i = 0; i < MAX_CD; i++) {
		if (PathExists(entry, core->CD[i]) ) {
			entry->found = true;
			return;
		}
	}

	printMessage("KEYImporter", "Cannot find %s...", WHITE, entry->name);
	printStatus( "ERROR", LIGHT_RED );
}
Example #16
0
bool DOS_CreateFile(char const * name,Bit16u attributes,Bit16u * entry,bool fcb) {
    // Creation of a device is the same as opening it
    // Tc201 installer
    if (DOS_FindDevice(name) != DOS_DEVICES)
        return DOS_OpenFile(name, OPEN_READ, entry, fcb);

    LOG(LOG_FILES,LOG_NORMAL)("file create attributes %X file %s",attributes,name);
    char fullname[DOS_PATHLENGTH];
    Bit8u drive;
    DOS_PSP psp(dos.psp());
    if (!DOS_MakeName(name,fullname,&drive)) return false;
    /* Check for a free file handle */
    Bit8u handle=DOS_FILES;
    Bit8u i;
    for (i=0; i<DOS_FILES; i++) {
        if (!Files[i]) {
            handle=i;
            break;
        }
    }
    if (handle==DOS_FILES) {
        DOS_SetError(DOSERR_TOO_MANY_OPEN_FILES);
        return false;
    }
    /* We have a position in the main table now find one in the psp table */
    *entry = fcb?handle:psp.FindFreeFileEntry();
    if (*entry==0xff) {
        DOS_SetError(DOSERR_TOO_MANY_OPEN_FILES);
        return false;
    }
    /* Don't allow directories to be created */
    if (attributes&DOS_ATTR_DIRECTORY) {
        DOS_SetError(DOSERR_ACCESS_DENIED);
        return false;
    }
    bool foundit=Drives[drive]->FileCreate(&Files[handle],fullname,attributes);
    if (foundit) {
        Files[handle]->SetDrive(drive);
        Files[handle]->AddRef();
        if (!fcb) psp.SetFileHandle(*entry,handle);
        return true;
    } else {
        if(!PathExists(name)) DOS_SetError(DOSERR_PATH_NOT_FOUND);
        else DOS_SetError(DOSERR_FILE_NOT_FOUND);
        return false;
    }
}
Example #17
0
bool CreateAllDirs(std::string path)
{

	std::vector<std::string> tocreate;
	std::string basepath = path;
	while(!PathExists(basepath))
	{
		tocreate.push_back(basepath);
		basepath = RemoveLastPathComponent(basepath);
		if(basepath.empty())
			break;
	}
	for(int i=tocreate.size()-1;i>=0;i--)
		if(!CreateDir(tocreate[i]))
			return false;
	return true;
}
Example #18
0
bool CreateAllDirs(std::string path)
{

	size_t pos;
	std::vector<std::string> tocreate;
	std::string basepath = path;
	while(!PathExists(basepath))
	{
		tocreate.push_back(basepath);
		pos = basepath.rfind('/');
		if(pos == std::string::npos)
			return false;
		basepath = basepath.substr(0,pos);
	}
	for(int i=tocreate.size()-1;i>=0;i--)
		CreateDir(tocreate[i]);
	return true;
}
void PathBehaviorEditor::OnBitmapButton3Click1(wxCommandEvent& event)
{
    gd::String newPathName = wxGetTextFromUser(_("Name of the new path:"), _("New path"), "newPath");

    if(PathExists(newPathName))
    {
        wxMessageBox(_("This path already exists."), _("Unable to create the path"));
        return;
    }

    PathInfo newPathInfo;
    newPathInfo.name = newPathName;
    newPathInfo.isGlobal = false;

    paths[newPathInfo.name] = newPathInfo;

    UpdateComboBoxWithPathsName();
    ChangePathOfPreview(newPathName);
}
Example #20
0
bool DOS_CreateFile(char const* name, Bit16u attributes, Bit16u* entry)
	{

	if (DOS_FindDevice(name) != DOS_DEVICES)											// Creating a device is the same as opening it
		return DOS_OpenFile(name, OPEN_READWRITE, entry);

	char fullname[DOS_PATHLENGTH];
	Bit8u drive;
	if (!DOS_MakeName(name, fullname, &drive))
		return false;
	Bit8u handle;
	for (handle = 0; handle < DOS_FILES; handle++)										// Check for a free file handle
		if (!Files[handle])
			break;
	if (handle == DOS_FILES)
		{
		DOS_SetError(DOSERR_TOO_MANY_OPEN_FILES);
		return false;
		}
	DOS_PSP psp(dos.psp());																// We have a position in the main table, now find one in the psp table
	*entry = psp.FindFreeFileEntry();
	if (*entry == 0xff)
		{
		DOS_SetError(DOSERR_TOO_MANY_OPEN_FILES);
		return false;
		}
	if (attributes&DOS_ATTR_DIRECTORY)													// Don't allow directories to be created
		{
		DOS_SetError(DOSERR_ACCESS_DENIED);
		return false;
		}
	if (Drives[drive]->FileCreate(&Files[handle], fullname, attributes))
		{ 
		Files[handle]->SetDrive(drive);
		Files[handle]->AddRef();
		psp.SetFileHandle(*entry, handle);
		return true;
		}
	DOS_SetError(PathExists(name) ? DOSERR_FILE_ALREADY_EXISTS : DOSERR_PATH_NOT_FOUND);
	return false;
	}
Example #21
0
static int InstallIcinga(void)
{
	std::string installDir = GetIcingaInstallPath();
	std::string dataDir = GetIcingaDataPath();

	if (!PathExists(dataDir)) {
		std::string sourceDir = installDir + "\\share\\skel" + std::string(1, '\0');
		std::string destinationDir = dataDir + std::string(1, '\0');

		SHFILEOPSTRUCT fop;
		fop.wFunc = FO_COPY;
		fop.pFrom = sourceDir.c_str();
		fop.pTo = destinationDir.c_str();
		fop.fFlags = FOF_NO_UI | FOF_NOCOPYSECURITYATTRIBS;

		if (SHFileOperation(&fop) != 0)
			return 1;

		MkDirP(dataDir + "/etc/icinga2/pki");
		MkDirP(dataDir + "/var/cache/icinga2");
		MkDirP(dataDir + "/var/lib/icinga2/pki");
		MkDirP(dataDir + "/var/lib/icinga2/agent/inventory");
		MkDirP(dataDir + "/var/lib/icinga2/api/config");
		MkDirP(dataDir + "/var/lib/icinga2/api/log");
		MkDirP(dataDir + "/var/lib/icinga2/api/repository");
		MkDirP(dataDir + "/var/lib/icinga2/api/zones");
		MkDirP(dataDir + "/var/log/icinga2/compat/archive");
		MkDirP(dataDir + "/var/log/icinga2/crash");
		MkDirP(dataDir + "/var/run/icinga2/cmd");
		MkDirP(dataDir + "/var/spool/icinga2/perfdata");
		MkDirP(dataDir + "/var/spool/icinga2/tmp");
	}

	ExecuteCommand("icacls", "\"" + dataDir + "\" /grant *S-1-5-20:(oi)(ci)m");
	ExecuteCommand("icacls", "\"" + dataDir + "\\etc\" /inheritance:r /grant:r *S-1-5-20:(oi)(ci)m *S-1-5-32-544:(oi)(ci)f");

	ExecuteIcingaCommand("--scm-install daemon");

	return 0;
}
void PathBehaviorEditor::OnBitmapButton5Click(wxCommandEvent& event)
{
    gd::String originalName = pathInfo->name;
    if(originalName == "")
    {
        wxMessageBox(_("Object's main path cannot be renamed"), _("Error"));
        return;
    }

    gd::String newName = wxGetTextFromUser(_("New path name:"), _("Rename a path"), originalName);

    if(PathExists(newName) && newName != originalName)
    {
        wxMessageBox(_("This path already exists."), _("Unable to rename the path"));
        return;
    }

    replace_key< std::map<gd::String, PathInfo> >(paths, originalName, newName);
    paths.at(newName).name = newName;

    UpdateComboBoxWithPathsName();
    ChangePathOfPreview(newName);
}
Example #23
0
SPECIALURLTYPE TransformUrl(wxString&Url)
{
  SPECIALURLTYPE ut = GetSpecialUrlType(Url);
  const wxString location = Url.Mid(ut & 0x0F);
  const wxString exePath = wxPathOnly(wxStandardPaths::Get().GetExecutablePath());

  if (SUT_BIN == ut)
  {
#ifdef __WXMSW__
    Url = BuildPath(exePath, location) + wxT(".exe");
    if (!PathExists(Url))
      Url = BuildPath(exePath, wxT("Bin"), location) + wxT(".exe");
#else
    Url = BuildPath(exePath, location);
#endif
  }
  else if (SUT_DOC == ut)
  {
#ifdef __WXMSW__
    wxString path = BuildPath(exePath, location);
#else
    wxString path = BuildPath(wxT(PREFIX_DOC), location);
#endif
    if ((!CanOpenChm() || !wxFileExists(path)) && 0 == location.CmpNoCase(wxT("NSIS.chm")))
    {
      path = BuildPath(wxPathOnly(path), wxT("Docs"), wxT("Manual.html")); // DOCTYPES=htmlsingle
      if (!wxFileExists(path))
        path = BuildPath(wxPathOnly(path), wxT("Contents.html")); // DOCTYPES=html (Not adding /Docs/ because it has already been appended)
    }
    Url = path;
  }
  else if (SUT_WEB == ut)
  {
    Url = location;
  }
  return ut;
}
Example #24
0
int DPTDriveBusy::drvBusy(int hba, int bus, int target, int lun)
{	char          * Targets[2];
	char         ** Dirs[sizeof(Targets)/sizeof(Targets[0])];
	char         ** Suffixes[sizeof(Targets)/sizeof(Targets[0])];
	int		        SuffixIndex;
	DPTDeviceList * Mounts = (DPTDeviceList *)NULL;
	int             RetVal = -1;

	/* Initialize the local structures */
	Targets[0] = getTargetString(hba, bus, target, lun);
	Dirs[0] = TargetStringDirs;
	Suffixes[0] = TargetStringSuffixes;
	Targets[1] = getTargetPath(hba, bus, target, lun);
	Dirs[1] = TargetPathDirs;
	Suffixes[1] = TargetPathSuffixes;

	for (SuffixIndex = 0;;) {
		while (Targets[0] == (char *)NULL) {
			int Index, NoneZero = 0;

			for (Index = sizeof(Targets)/sizeof(Targets[0]); Index; --Index) {
				if ((Targets[Index-2] = Targets[Index-1]) != (char *)NULL) {
					++NoneZero;
				}
				Targets[Index-1] = (char *)NULL;
				Dirs[Index-2] = Dirs[Index-1];
				Suffixes[Index-2] = Suffixes[Index-1];
			}
			if (NoneZero == 0) {
				break;
			}
		}
		if (Targets[0] == (char *)NULL) {
			break;
		}

		/* Check if the Dirs/Targets entry exists */
		{	char * name = new char[strlen(Dirs[0][0]) + strlen(Targets[0])
			  + strlen(Suffixes[0][SuffixIndex]) + 1];

			if (name == (char *)NULL) {
				RetVal = -2;
				break;
			}
			(void)strcat(strcat(strcpy(name,
			  Dirs[0][0]), Targets[0]), Suffixes[0][SuffixIndex]);
			switch(PathExists(name)) {
	    	case PathExists_Exists:
		    case PathExists_Read:
		    case PathExists_Open:
				/* Check if the Dirs/Target entry is mounted */
				if (Mounts == (DPTDeviceList *)NULL) {
					FILE * fp = SafePopenRead("mount | sed -n '"
					  "s/^\\([^ 	][^ 	]*\\)[ 	][ 	]*on[ 	][ 	]*\\([^ 	][^ 	]*\\).*/\\1 \\2/p'");
					char * Buffer = new char[512];

					while (fgets (Buffer, 512, fp)) {
						if (newDeviceList (&Mounts, Buffer)) {
							RetVal = -2;
						}
					}
					SafePclose(fp);
					if (RetVal == -1) {
						RetVal = 0;
					}
#					if (defined(DEBUG) && (DEBUG > 0))
						if (Mounts != (DPTDeviceList *)NULL) {
						    DPTDeviceList * List = Mounts;
							DPTDeviceList * Link;

						    printf ("Mount list:\n");
							do {
								printf ("%s", List->Name);
								if ((List->Major == -2)
								 && (List->Minor == -2)) {
									printf ("/");
								} else if ((List->Major != -1)
								 || (List->Minor != -1)) {
									printf ("(%d,%d)",
									  List->Major, List->Minor);
								}
								if ((Link = List->Link)
								  == (DPTDeviceList *)NULL) {
									printf ("\n");
									Link = List->Next;
								} else {
									printf (", ");
								}
							} while ((List = Link) != (DPTDeviceList *)NULL);
						}
#					endif
				}
				/* We have an initialized mount database, search! */
				{
					DPTDeviceList * Link;
					DPTDeviceList * Names = (DPTDeviceList *)NULL;

					newDeviceList (&Names, name);
					for (Link = Mounts; Link != (DPTDeviceList *)NULL; ) {
						DPTDeviceList * Next;
                        DPTDeviceList *Name;
						for (Name = Names;
						  (Name = Name->Link) != (DPTDeviceList *)NULL; ) {
							/* Same name, or same device */
							if ((strcmp (Name->Name, Link->Name) == 0)
							 || ((Name->Major == Link->Major)
							  && (Name->Minor == Link->Minor))) {
								break;
							}
						}
						if (Name != (DPTDeviceList *)NULL) {
							RetVal = 1;
							break;
						}
						if ((Next = Link->Link) == (DPTDeviceList *)NULL) {
							Next = Link->Next;
						}
						Link = Next;
					}
					deleteDeviceList (Names);
				}
				break;
				
		    case PathExists_Busy:
				RetVal = 1;	/* It's busy even before we hit the ground */
			case PathExists_None:
				break;
			}
			delete [] name;
		}

		if ((RetVal != -1) && (RetVal != 0)) {
			break;
		}
		/* Try next */
		if (Suffixes[0][++SuffixIndex] == (char *)NULL) {
			SuffixIndex = 0;
			if ((++(Dirs[0]))[0] == (char *)NULL) {
				delete [] Targets[0];
				Targets[0] = (char *)NULL;
			}
		}
	}
	/* Free up resources */
	{	int Index;

		for (Index = 0; Index < (sizeof(Targets)/sizeof(Targets[0])); ++Index) {
			if (Targets[Index] != (char *)NULL) {
				delete [] Targets[Index];
			}
		}
	}
	deleteDeviceList (Mounts);

	return (RetVal);
}
Example #25
0
bool install_util::IsFolder(const wstring& path) {
  return PathExists(path) && ((GetFileAttributes(path.c_str()) & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY);
}
TEST(System, PathExistsWithBadPath) {
  SystemMock sys;
  EXPECT_FALSE(PathExists("/tmp/foo"));
}
Example #27
0
static
rc_t open_and_run (Context * context)
{
    KDirectory * pwd;
    rc_t rc;

    rc = KDirectoryNativeDir (&pwd);
    if (rc)
        LOGERR (klogFatal, rc, "Unable to open file system");
    else
    {
        if (PathExists (pwd, kptDile, context->file_path))
        {
            if (PathExists (pwd, kptDile, context->file_path))
            {
                VDBManager * vmgr;

                rc = VDBManagerMakeUpdate (&vmgr, pwd);
                if (rc)
                    LOGERR (kptInt, "Failed to create a database manager");
                else
                {
                    VSchema * vschema;

                    rc = VDBManagerMakeSchema (vmgr, &vschema);
                    if (rc)
                        LOGERR (kptInt, "Failed to create schema");
                    else
                    {
                        rc = VSchemaParseFile (vschema, args->schema);
                        if (rc)
                            PLOGERR (klogFatal, (klogFatal, 
                                                 "Unable to parse schema file ($S)",
                                                 "S=%s", args->schema));
                        else
                        {
                            VTable * vtable;
                            rc = VDBManagerOpenTableUpdate (vmgr, &vtable, SCHEMA, args->table);
                            if (rc)
                                PLOGERR (klogFatal, (klogFatal, "Unable to open table ($T)",
                                             "T=%s", args->table));
                            else
                            {

                        
                                VTableRelease (vtable);
                            }
                        }
                        VSchemaRelease (vschema);
                    }
                    VDBManagerRelease (vmgr);
                }
            }
            else
                PLOGERR (kptFatal, (kptFatal, "table paramaeter is not a table directory ($F)",
                                    "F=%s", args->table));
        }
        else
            PLOGERR (kptFatal, (kptFatal, "file paramaeter is not a file ($F)",
                                "F=%s", context->file_path));



        KPathType pt;

        pt = KDirectoryPathType (arg->file);
        if ((pt & ~kptAlias) != kptFile)
        else
        {
        }
        KDirectoryRelease (pwd);
    }
    return rc;
}
//  27-Aug-2004 SFK		Created
void CopyLogsMenuOption()
{                                 

    static char szDfltRootPath[PATH_LEN+1] = "";
    static char szDfltCurrentDbPath[PATH_LEN+1] = "";                   
    static BOOL bFirst = TRUE;
    
	char szCurrentDbPath[PATH_LEN+1] = "";    
	char szMainCurrentDbPath[PATH_LEN+1] = "";    
    char szRootBackupPath[PATH_LEN+1] = "";
	char szMainBackupPath[PATH_LEN+1] = "";
    unsigned long ulDirSize, ulDiskSize, ulDiskAvailable;
    BOOL bRoom;     
    int status;
    char *pStr;

    
    GUI_ACTION DlgReturn;         
    CGFmtStr msg;

	SetCurrentDrive();    
    GetDbName(szCurrentDbPath);
    
   /* ------------------------------------------------------------------
    *	First time or when change databases, get the default values
    *	from the .ini file else use the last successful values.
    * ------------------------------------------------------------------*/
    if ((bFirst == TRUE) || (!SameDb(szDfltCurrentDbPath))) {
    	pStr = pRAD_Init->Get_LogCopy_To_Path(); 
		MyStrnCpy(szDfltRootPath, pStr, PATH_LEN); 
   		bFirst = FALSE;
    	strcpy(szDfltCurrentDbPath, szCurrentDbPath);
	}
	
	strcpy(szRootBackupPath, szDfltRootPath);

   /* ------------------------------------------------------------------
    *	Define the buttons and actions in the dialog box
    * ----------------------------------------------------------------*/
    CGUI_Dlg BackupDbDlg(IDD_FILE_COPY_LOGS, NULL, DLG_POSN_NO_SAVE);
    if (BackupDbDlg.IsValid()) {
		BackupDbDlg.DefinePushBtn(IDCANCEL, GUI_CANCEL);
		BackupDbDlg.DefinePushBtn(IDOK, GUI_OK);
		BackupDbDlg.DefinePushBtn(IDUPDATE, GUI_NONE, UpdateINI_Parms);              
			                                               
		BackupDbDlg.DefineFldTxt(IDC_CLOG_EDIT_NEW_PATH, szRootBackupPath, PATH_LEN);
			
		BackupDbDlg.SetFocus(IDOK);
		
	    DlgReturn = BackupDbDlg.Go();
		    
	    if (DlgReturn == GUI_OK) {  
		    	
	    	BackupDbDlg.RetrieveAllControlValues();

		   /* ------------------------------------------------------------------
		    *	Remove spaces, check length
		    * ----------------------------------------------------------------*/
	    	if (PathCopy(szMainBackupPath, szRootBackupPath) != TRUE) return;
	    	strcat(szMainBackupPath, "logs\\rad\\");

	    	if (PathCopy(szMainCurrentDbPath, szCurrentDbPath) != TRUE) return;
	    	strcat(szMainCurrentDbPath, "logs\\rad\\");

		   /* ------------------------------------------------------------------
		    *	See if the new path exists, if not make it.  If can't make it give
		    *	reason why.
		    * ----------------------------------------------------------------*/
		    status = PathExists(szMainBackupPath); // returns TRUE, uiPATH_TOO_LONG_ERR, uiDRIVE_DOES_NOT_EXIST_ERR oruiPATH_DOES_NOT_EXIST_ERR
		    if ( status == uiPATH_DOES_NOT_EXIST_ERR) {
		    	status = AskAndMakePath(szMainBackupPath);
		    	if (status != TRUE) return;
		    }	
		    if ( status != TRUE) {
		    	RadReviewMsg(status, (const char *)szMainBackupPath);
				return;
			}	

		   /* ------------------------------------------------------------------
		    *	See if a log file exists at the location specified.  If yes,
		    *	see if they want to overwrite it.
		    * ----------------------------------------------------------------*/
		    if (FileExists(szMainBackupPath, "RadReviewLog.txt") == TRUE) {
		    	status = AskOverwriteQuestion(szMainBackupPath);
		    	if (status == FALSE) return;
		    }	
		    
		   /* ------------------------------------------------------------------
		    *	Figure out how many bytes will need to be copied and if there
		    *	is room on the destination drive.  (Destination drive must have
		    *	directory size + 10000 to allow for directory entries, etc.)
		    * ----------------------------------------------------------------*/
		    if (GetDirSize(szMainCurrentDbPath, "*.*", &ulDirSize) != TRUE) return;	/* check number of bytes filled in szCurrentDbPath */
			
			// Customize for COMs, if don't write to this log directory

		    if (GetDriveSize(szMainBackupPath, &ulDiskSize, &ulDiskAvailable) != TRUE) return;	/* check number of bytes available on drive */
			
			bRoom = TRUE;
			if ((ulDirSize + 10000) > ulDiskAvailable) bRoom = FALSE;	    
		    	    
		    if (bRoom == FALSE) {
		    	if (AskNotEnoughRoomQuestion(ulDirSize, ulDiskAvailable, szMainBackupPath) == FALSE) return;
		    }
		    
		   /* ------------------------------------------------------------------
		    *	Close the current database in case are trying to copy it.
		    *	Copy the data and show progress. Inform of the results of the copy.	
		    * ----------------------------------------------------------------*/
		    GetDbName(szCurrentDbPath);
			_flushall();
			    
		    status = CopyDirectory(szMainCurrentDbPath, szMainBackupPath);

			// Customize for COMs, if don't write to this log directory

		    if (status != TRUE) { 
		    	RadReviewMsg(uiCOPY_DB_ERR, (const char *)szCurrentDbPath, (const char *)szRootBackupPath);
		    }
		    else {	
		    	MyStrnCpy(szDfltRootPath,szRootBackupPath, PATH_LEN);	// remember the default for next time
				msg.Printf("Logs copied to %s.", szRootBackupPath);	
			    GUI_MsgBox(msg, GUI_ICON_INFO);
		    }	

	    }	
	}    
}   		                                 
Example #29
0
const bool OTPaths::ConfirmCreateFolder(const OTString & strExactPath, bool & out_Exists, bool & out_IsNew)
{
	const bool bExists = (strExactPath.Exists() && !strExactPath.Compare(""));
	OT_ASSERT_MSG(bExists,"OTPaths::ConfirmCreateFolder: Assert failed: no strFolderName\n");

	std::string l_strExactPath(strExactPath.Get());

	if ('/' != *l_strExactPath.rbegin()) return false; // not a directory.

	// Confirm If Directory Exists Already
	out_Exists = PathExists(strExactPath);

	if (out_Exists)
	{
		out_IsNew = false;
		return true;  // Already Have Folder, lets retun true!
	}
	else 
	{
		// It dosn't exist: lets create it.

#ifdef _WIN32
		bool bCreateDirSuccess = (_mkdir(strExactPath.Get()) == 0);
#else
		bool bCreateDirSuccess = (mkdir(strExactPath.Get(), 0700) == 0);
#endif

		if (!bCreateDirSuccess) 
		{
			OTLog::vError("OTPaths::ConfirmCreateFolder: Unable To Confirm "
				"Created Directory %s.\n", strExactPath.Get());
			out_IsNew = false;
			out_Exists = false;
			return false;
		}

		// At this point if the folder still doesn't exist, nothing we can do. We
		// already tried to create the folder, and SUCCEEDED, and then STILL failed 
		// to find it (if this is still false.)

		else 
		{
			bool bCheckDirExist = PathExists(strExactPath);

			if (!bCheckDirExist) 
			{
				OTLog::vError("OTPaths::ConfirmCreateFolder: "
					"Unable To Confirm Created Directory %s.\n", 
					strExactPath.Get());
				out_IsNew = false;
				out_Exists = false;
				return false;
			}
			else
			{
				out_IsNew = true;
				out_Exists = false;
				return true;  // We have Created and checked the Folder
			}
		}
		return false; // should never happen.
	}
}
Example #30
0
bool DOS_OpenFile(char const * name,Bit8u flags,Bit16u * entry,bool fcb) {
    /* First check for devices */
    if (flags>2) LOG(LOG_FILES,LOG_ERROR)("Special file open command %X file %s",flags,name);
    else LOG(LOG_FILES,LOG_NORMAL)("file open command %X file %s",flags,name);

    DOS_PSP psp(dos.psp());
    Bit16u attr = 0;
    Bit8u devnum = DOS_FindDevice(name);
    bool device = (devnum != DOS_DEVICES);
    if(!device && DOS_GetFileAttr(name,&attr)) {
        //DON'T ALLOW directories to be openened.(skip test if file is device).
        if((attr & DOS_ATTR_DIRECTORY) || (attr & DOS_ATTR_VOLUME)) {
            DOS_SetError(DOSERR_ACCESS_DENIED);
            return false;
        }
    }

    char fullname[DOS_PATHLENGTH];
    Bit8u drive;
    Bit8u i;
    /* First check if the name is correct */
    if (!DOS_MakeName(name,fullname,&drive)) return false;
    Bit8u handle=255;
    /* Check for a free file handle */
    for (i=0; i<DOS_FILES; i++) {
        if (!Files[i]) {
            handle=i;
            break;
        }
    }
    if (handle==255) {
        DOS_SetError(DOSERR_TOO_MANY_OPEN_FILES);
        return false;
    }
    /* We have a position in the main table now find one in the psp table */
    *entry = fcb?handle:psp.FindFreeFileEntry();

    if (*entry==0xff) {
        DOS_SetError(DOSERR_TOO_MANY_OPEN_FILES);
        return false;
    }
    bool exists=false;
    if (device) {
        Files[handle]=new DOS_Device(*Devices[devnum]);
    } else {
        exists=Drives[drive]->FileOpen(&Files[handle],fullname,flags);
        if (exists) Files[handle]->SetDrive(drive);
    }
    if (exists || device ) {
        Files[handle]->AddRef();
        if (!fcb) psp.SetFileHandle(*entry,handle);
        return true;
    } else {
        //Test if file exists, but opened in read-write mode (and writeprotected)
        if(((flags&3) != OPEN_READ) && Drives[drive]->FileExists(fullname))
            DOS_SetError(DOSERR_ACCESS_DENIED);
        else {
            if(!PathExists(name)) DOS_SetError(DOSERR_PATH_NOT_FOUND);
            else DOS_SetError(DOSERR_FILE_NOT_FOUND);
        }
        return false;
    }
}