예제 #1
0
 private string SafeReadContents(string file, out FileInfoBase fileInfo)
 {
     try
     {
         fileInfo = this._fileSystem.FileInfo.FromFileName(file);
         return(this._fileSystem.File.ReadAllText(file));
     }
     catch (IOException)
     {
         fileInfo = this._fileSystem.FileInfo.FromFileName(file);
         var tempFile = Path.Combine(Path.GetTempPath(), fileInfo.Name);
         try
         {
             fileInfo.CopyTo(tempFile, true);
             return(this._fileSystem.File.ReadAllText(tempFile));
         }
         finally
         {
             if (this._fileSystem.File.Exists(tempFile))
             {
                 this._fileSystem.File.Delete(tempFile);
             }
         }
     }
 }
예제 #2
0
        private void SmartCopyFile(FileInfoBase sourceFile, string path)
        {
            var destFile = sourceFile.CopyTo(path, overwrite: true);

            if (!_options.CopyMetaData)
            {
                return;
            }

            // we remove the existing attributes, as 'read-only' will cause an exception when writing 'creationtime' an others.
            var removeattr = sourceFile.Attributes;

            destFile.Attributes = 0;

            destFile.CreationTimeUtc   = sourceFile.CreationTimeUtc;
            destFile.LastWriteTimeUtc  = sourceFile.LastWriteTimeUtc;
            destFile.LastAccessTimeUtc = sourceFile.LastAccessTimeUtc;
            destFile.Attributes        = removeattr;
        }