コード例 #1
0
ファイル: winUtils.cpp プロジェクト: MiKTeX/miktex
void Utils::CanonicalizePathName(PathName& path)
{
  wchar_t szFullPath[BufferSizes::MaxPath];
  DWORD n = GetFullPathNameW(path.ToWideCharString().c_str(), BufferSizes::MaxPath, szFullPath, nullptr);
  if (n == 0)
  {
    MIKTEX_FATAL_WINDOWS_ERROR_2("GetFullPathNameW", "path", path.ToString());
  }
  if (n >= BufferSizes::MaxPath)
  {
    BUF_TOO_SMALL();
  }
  path = szFullPath;
}
コード例 #2
0
ファイル: winUtils.cpp プロジェクト: MiKTeX/miktex
bool Utils::SupportsHardLinks(const PathName& path)
{
  DWORD fileSystemFlags;
  wchar_t fileSystemName[_MAX_PATH];
  PathName root = path.GetMountPoint();
  if (GetVolumeInformationW(root.ToWideCharString().c_str(), nullptr, 0, nullptr, nullptr, &fileSystemFlags, fileSystemName, _MAX_PATH) == 0)
  {
    MIKTEX_FATAL_WINDOWS_ERROR_2("GetVolumeInformationW", "root", root.ToString());
  }
  if (WindowsVersion::IsWindows7OrGreater())
  {
    return (fileSystemFlags & FILE_SUPPORTS_HARD_LINKS) != 0;
  }
  else
  {
    return _wcsicmp(fileSystemName, L"NTFS") == 0;
  }
}
コード例 #3
0
ファイル: files.cpp プロジェクト: bngabonziza/miktex
void
File::Delete (/*[in]*/ const PathName &		path,
                       /*[in]*/ bool			tryHarder,
                       /*[in]*/ bool			updateFndb)
{
    if (updateFndb
            && SessionImpl::GetSession()->IsTEXMFFile(path.Get(), 0, 0)
            && Fndb::FileExists(path))
    {
        Fndb::Remove (path);
    }

    FileAttributes attributes = File::GetAttributes(path);

    bool done;

    try
    {
        if ((attributes & FileAttributes::ReadOnly) != 0)
        {
            attributes &= ~ FileAttributes(FileAttributes::ReadOnly);
            File::SetAttributes (path, attributes);
        }
        File::Delete (path);
        done = true;
    }

    catch (const UnauthorizedAccessException &)
    {
#if defined(MIKTEX_WINDOWS)
        if (! tryHarder)
        {
            throw;
        }
        done = false;
#else
        throw;
#endif
    }

#if defined(MIKTEX_WINDOWS)
    if (! done)
    {
        // move the file out of the way
        PathName absPath (path);
        if (! Utils::IsAbsolutePath(path.Get()))
        {
            absPath.MakeAbsolute ();
        }
        wchar_t szDir[BufferSizes::MaxPath];
        if (IsWindowsNT())
        {
            DllProc3<BOOL, LPCWSTR, LPWSTR, DWORD>
            getVolumePathNameW ("Kernel32.dll",  "GetVolumePathNameW");
            if (! getVolumePathNameW(absPath.ToWideCharString().c_str(),
                                     szDir,
                                     BufferSizes::MaxPath))
            {
                FATAL_WINDOWS_ERROR ("GetVolumePathNameA", absPath.Get());
            }
        }
        else
        {
#if defined(MIKTEX_SUPPORT_LEGACY_WINDOWS)
            dir = absPath;
            dir.RemoveFileSpec ();
#else
            UNSUPPORTED_PLATFORM ();
#endif
        }
        wchar_t szTemp[BufferSizes::MaxPath];
        if (GetTempFileNameW(szDir, L"mik", 0, szTemp) == 0)
        {
            FATAL_WINDOWS_ERROR ("GetTempFileNameW", WU_(szDir));
        }
        File::Delete (szTemp);
        File::Move (absPath, szTemp);
        SessionImpl::GetSession()->ScheduleFileRemoval (PathName(szTemp).Get());
    }
#endif
}