예제 #1
0
        /// <summary>
        ///     Try getting the attributes of a file.
        /// </summary>
        /// <returns>Returns false if the file doesn't exist.</returns>
        public static bool TryGetFileAttributes(this IAbsFileSystem fileSystem, AbsolutePath path, out FileAttributes attributes)
        {
            if (!fileSystem.FileExists(path))
            {
                attributes = default;
                return(false);
            }

            try
            {
                attributes = fileSystem.GetFileAttributes(path);
            }
            catch (FileNotFoundException)
            {
                // We checked file existence at the top of the method, but due to a race condition, the file can be gone
                // at the point when we tried getting attributes.
                // Current implementation tries it best to avoid unnecessary first chance exceptions, but can't eliminate them completely.
                attributes = default;
                return(false);
            }

            return(true);
        }