[xharness] Be resilient when trying to copying contents from an inexistent file. (#4676)

Should fix this (or at the very least not prevent xharness from writing out the report):

    21:07:30.3947450 Failed to write log: System.IO.FileNotFoundException: Could not find file '/Users/builder/Library/Logs/CoreSimulator/6DA2ED3C-B1FA-4D0B-9DD6-113E5F9A1381/system.log'.
    File name: '/Users/builder/Library/Logs/CoreSimulator/6DA2ED3C-B1FA-4D0B-9DD6-113E5F9A1381/system.log'
        at System.IO.__Error.WinIOError (System.Int32 errorCode, System.String maybeFullPath) [0x00207] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-02/external/bockbuild/builds/mono-x64/mcs/class/referencesource/mscorlib/system/io/__error.cs:188
        at System.IO.FileInfo.get_Length () [0x00038] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-02/external/bockbuild/builds/mono-x64/mcs/class/referencesource/mscorlib/system/io/fileinfo.cs:171
        at xharness.CaptureLog.Capture () [0x0004a] in /Users/builder/jenkins/workspace/xamarin-macios/xamarin-macios/tests/xharness/Log.cs:334
        at xharness.CaptureLog.Flush () [0x00008] in /Users/builder/jenkins/workspace/xamarin-macios/xamarin-macios/tests/xharness/Log.cs:373
        at xharness.Jenkins.GenerateReportImpl (System.IO.Stream stream, System.IO.StreamWriter markdown_summary) [0x017db] in /Users/builder/jenkins/workspace/xamarin-macios/xamarin-macios/tests/xharness/Jenkins.cs:2012
        at xharness.Jenkins.GenerateReport (System.Boolean only_if_ci) [0x00075] in /Users/builder/jenkins/workspace/xamarin-macios/xamarin-macios/tests/xharness/Jenkins.cs:1313
This commit is contained in:
Rolf Bjarne Kvinge 2018-08-22 16:54:19 +02:00 коммит произвёл GitHub
Родитель 1d5c334a89
Коммит ea4909034b
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 6 добавлений и 1 удалений

Просмотреть файл

@ -325,7 +325,12 @@ namespace xharness
{ {
if (startPosition == 0 || entire_file) if (startPosition == 0 || entire_file)
return; return;
if (!File.Exists (CapturePath)) {
File.WriteAllText (Path, $"Could not capture the file '{CapturePath}' because it does not exist.");
return;
}
var currentEndPosition = endPosition; var currentEndPosition = endPosition;
if (currentEndPosition == 0) if (currentEndPosition == 0)
currentEndPosition = new FileInfo (CapturePath).Length; currentEndPosition = new FileInfo (CapturePath).Length;