You've already forked linux-packaging-mono
Imported Upstream version 4.2.0.179
Former-commit-id: 4610231f55806d2a05ed69e5ff3faa7336cc1479
This commit is contained in:
committed by
Jo Shields
parent
aa7da660d6
commit
c042cd0c52
47
external/referencesource/System.Configuration/System/Configuration/FileUtil.cs
vendored
Normal file
47
external/referencesource/System.Configuration/System/Configuration/FileUtil.cs
vendored
Normal file
@ -0,0 +1,47 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="FileUtil.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Configuration {
|
||||
using System;
|
||||
using System.IO;
|
||||
using Microsoft.Win32;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
static internal class FileUtil {
|
||||
const int HRESULT_WIN32_FILE_NOT_FOUND = unchecked((int)0x80070002);
|
||||
const int HRESULT_WIN32_PATH_NOT_FOUND = unchecked((int)0x80070003);
|
||||
|
||||
//
|
||||
// Use to avoid the perf hit of a Demand when the Demand is not necessary for security.
|
||||
//
|
||||
// If trueOnError is set, then return true if we cannot confirm that the file does NOT exist.
|
||||
//
|
||||
internal static bool FileExists(string filename, bool trueOnError) {
|
||||
UnsafeNativeMethods.WIN32_FILE_ATTRIBUTE_DATA data;
|
||||
bool ok = UnsafeNativeMethods.GetFileAttributesEx(filename, UnsafeNativeMethods.GetFileExInfoStandard, out data);
|
||||
if (ok) {
|
||||
// The path exists. Return true if it is a file, false if a directory.
|
||||
return (data.fileAttributes & (int) FileAttributes.Directory) != (int) FileAttributes.Directory;
|
||||
}
|
||||
else {
|
||||
if (!trueOnError) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
// Return true if we cannot confirm that the file does NOT exist.
|
||||
int hr = Marshal.GetHRForLastWin32Error();
|
||||
if (hr == HRESULT_WIN32_FILE_NOT_FOUND || hr == HRESULT_WIN32_PATH_NOT_FOUND) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user