mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-26 01:25:42 -05:00
Removing the FileStreamWrapper as it is unecessary (#156)
This commit is contained in:
46
src/Microsoft.SqlTools.ServiceLayer/Utility/FileUtils.cs
Normal file
46
src/Microsoft.SqlTools.ServiceLayer/Utility/FileUtils.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
using System;
|
||||
using System.IO;
|
||||
namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
||||
{
|
||||
internal static class FileUtils
|
||||
{
|
||||
/// <summary>
|
||||
/// Checks if file exists and swallows exceptions, if any
|
||||
/// </summary>
|
||||
/// <param name="path"> path of the file</param>
|
||||
/// <returns></returns>
|
||||
internal static bool SafeFileExists(string path)
|
||||
{
|
||||
try
|
||||
{
|
||||
return File.Exists(path);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// Swallow exception
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes a file and swallows exceptions, if any
|
||||
/// </summary>
|
||||
/// <param name="path"></param>
|
||||
internal static void SafeFileDelete(string path)
|
||||
{
|
||||
try
|
||||
{
|
||||
File.Delete(path);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// Swallow exception, do nothing
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user