Skip to content

Commit

Permalink
#1833 windows fixxes
Browse files Browse the repository at this point in the history
  • Loading branch information
qdraw committed Dec 19, 2024
1 parent 0ae4786 commit a95133b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,15 @@ public async Task<FfmpegDownloadStatus> 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;
}
Expand All @@ -67,9 +70,9 @@ public async Task<FfmpegDownloadStatus> 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;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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 )
{
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down

0 comments on commit a95133b

Please sign in to comment.