main
cs 59 lines 3.14 KB
Raw
1 // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
2
3 namespace WixToolset.Extensibility.Services
4 {
5 using System;
6 using System.IO;
7 using WixToolset.Data;
8
9 /// <summary>
10 /// Abstracts basic file system operations.
11 /// </summary>
12 public interface IFileSystem
13 {
14 /// <summary>
15 /// Copies a file.
16 /// </summary>
17 /// <param name="sourceLineNumbers">Optional source line number requiring the copy.</param>
18 /// <param name="source">The file to copy.</param>
19 /// <param name="destination">The destination file.</param>
20 /// <param name="allowHardlink">Allow hardlinks.</param>
21 void CopyFile(SourceLineNumber sourceLineNumbers, string source, string destination, bool allowHardlink);
22
23 /// <summary>
24 /// Deletes a file.
25 /// </summary>
26 /// <param name="sourceLineNumbers">Optional source line number requiring the delete.</param>
27 /// <param name="source">The file to delete.</param>
28 /// <param name="throwOnError">Indicates the file must be deleted. Default is a best effort delete.</param>
29 /// <param name="maxRetries">Maximum retry attempts. Default is 4.</param>
30 void DeleteFile(SourceLineNumber sourceLineNumbers, string source, bool throwOnError = false, int maxRetries = 4);
31
32 /// <summary>
33 /// Moves a file.
34 /// </summary>
35 /// <param name="sourceLineNumbers">Optional source line number requiring the move.</param>
36 /// <param name="source">The file to move.</param>
37 /// <param name="destination">The destination file.</param>
38 void MoveFile(SourceLineNumber sourceLineNumbers, string source, string destination);
39
40 /// <summary>
41 /// Opens a file.
42 /// </summary>
43 /// <param name="sourceLineNumbers">Optional source line number requiring the file.</param>
44 /// <param name="path">The file to open.</param>
45 /// <param name="mode">A System.IO.FileMode value that specifies whether a file is created if one does not exist, and determines whether the contents of existing files are retained or overwritten.</param>
46 /// <param name="access">A System.IO.FileAccess value that specifies the operations that can be performed on the file.</param>
47 /// <param name="share">A System.IO.FileShare value specifying the type of access other threads have to the file.</param>
48 FileStream OpenFile(SourceLineNumber sourceLineNumbers, string path, FileMode mode, FileAccess access, FileShare share);
49
50 /// <summary>
51 /// Executes an action and retries on any exception a few times with short pause
52 /// between each attempt. Primarily intended for use with file system operations
53 /// that might get interrupted by external systems (usually anti-virus).
54 /// </summary>
55 /// <param name="action">Action to execute.</param>
56 /// <param name="maxRetries">Maximum retry attempts. Default is 4.</param>
57 void ExecuteWithRetries(Action action, int maxRetries = 4);
58 }
59 }