From a95133b9aee2f181d89023580ae73770a8446422 Mon Sep 17 00:00:00 2001 From: Dion Date: Thu, 19 Dec 2024 11:05:16 +0100 Subject: [PATCH] #1833 windows fixxes --- .../GetDependencies/FfMpegDownloadBinaries.cs | 9 ++++--- .../GetDependencies/FfMpegChmodTests.cs | 24 +++++++++++++++---- .../GetDependencies/FfMpegDownloadTest.cs | 4 ++++ 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/starsky/starsky.foundation.video/GetDependencies/FfMpegDownloadBinaries.cs b/starsky/starsky.foundation.video/GetDependencies/FfMpegDownloadBinaries.cs index a2fb2308c..0ee241c69 100644 --- a/starsky/starsky.foundation.video/GetDependencies/FfMpegDownloadBinaries.cs +++ b/starsky/starsky.foundation.video/GetDependencies/FfMpegDownloadBinaries.cs @@ -39,12 +39,15 @@ public async Task Download( int retryInSeconds = 15) { var (binaryIndex, baseUrls) = binaryIndexKeyValuePair; + if ( binaryIndex?.FileName == null ) { return FfmpegDownloadStatus.DownloadBinariesFailedMissingFileName; } - if ( _hostFileSystemStorage.ExistFile(_ffmpegExePath.GetExePath(currentArchitecture)) ) + var exePath = _ffmpegExePath.GetExePath(currentArchitecture); + + if ( _hostFileSystemStorage.ExistFile(exePath) ) { return FfmpegDownloadStatus.Ok; } @@ -67,9 +70,9 @@ public async Task Download( _zipper.ExtractZip(zipFullFilePath, _ffmpegExePath.GetExeParentFolder(currentArchitecture)); - if ( !_hostFileSystemStorage.ExistFile(_ffmpegExePath.GetExePath(currentArchitecture)) ) + if ( !_hostFileSystemStorage.ExistFile(exePath) ) { - _logger.LogError($"Zipper failed {_ffmpegExePath.GetExePath(currentArchitecture)}"); + _logger.LogError($"Zipper failed {exePath}"); return FfmpegDownloadStatus.DownloadBinariesFailedZipperNotExtracted; } diff --git a/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegChmodTests.cs b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegChmodTests.cs index ed2b91c90..3a4cb8d3e 100644 --- a/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegChmodTests.cs +++ b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegChmodTests.cs @@ -1,3 +1,4 @@ +using System; using System.IO; using System.Linq; using System.Threading.Tasks; @@ -42,17 +43,29 @@ private void CreateFile() var stream = StringToStreamHelper.StringToStream("#!/bin/bash\necho Fake Ffmpeg"); _hostFileSystemStorage.WriteStream(stream, _ffmpegExePath.GetExePath("linux-x64")); + stream.Dispose(); var result = Zipper.ExtractZip([.. CreateAnExifToolWindows.Bytes]); var (_, item) = result.FirstOrDefault(p => p.Key.Contains("exiftool")); + _hostFileSystemStorage.CreateDirectory(_ffmpegExePath.GetExeParentFolder("win-x64")); + _hostFileSystemStorage.WriteStream(new MemoryStream(item), - Path.Combine(_ffmpegExePath.GetExeParentFolder("linux-x64"), "chmod.exe")); + Path.Combine(_ffmpegExePath.GetExeParentFolder("win-x64"), "chmod.exe")); } private void DeleteFile() { - _hostFileSystemStorage.FolderDelete(_parentFolder); + _hostFileSystemStorage.FileDelete(_ffmpegExePath.GetExePath("win-x64")); + + try + { + _hostFileSystemStorage.FolderDelete(_parentFolder); + } + catch ( UnauthorizedAccessException ) + { + // do nothing + } } [TestMethod] @@ -104,7 +117,7 @@ public async Task Chmod_ShouldReturnFalse_WhenCommandFails__UnixOnly() } [TestMethod] - public async Task Chmod_ShouldReturnFalse_WhenCommandSucceed__WindowsOnly() + public async Task Chmod_ShouldReturnTrue_WhenCommandSucceed__WindowsOnly() { if ( !_isWindows ) { @@ -115,11 +128,14 @@ public async Task Chmod_ShouldReturnFalse_WhenCommandSucceed__WindowsOnly() CreateFile(); var path = Path.Combine(_ffmpegExePath.GetExeParentFolder("win-x64"), "chmod.exe"); + + Console.WriteLine("test> " + path); + var sut = new FfMpegChmod(new FakeSelectorStorage(new FakeIStorage([], [path])), new FakeIWebLogger()) { CmdPath = path }; - var result = await sut.Chmod("/_not_found_path/to/ffmpeg"); + var result = await sut.Chmod(path); Assert.IsTrue(result); DeleteFile(); diff --git a/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadTest.cs b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadTest.cs index b2a4273b5..6ce46b650 100644 --- a/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadTest.cs +++ b/starsky/starskytest/starsky.foundation.video/GetDependencies/FfMpegDownloadTest.cs @@ -60,6 +60,10 @@ private static FfmpegBinariesIndex CreateExampleFile(string sha256 = "invalid-sh Architecture = "win-x64", FileName = "mock_test.zip", Sha256 = sha256 }, new BinaryIndex + { + Architecture = "win-arm64", FileName = "mock_test.zip", Sha256 = sha256 + }, + new BinaryIndex { Architecture = "osx-x64", FileName = "mock_test.zip", Sha256 = sha256 },