【发布时间】:2022-08-11 16:33:14
【问题描述】:
我正在尝试克隆一个包含符号链接的 git 存储库,然后使用以下代码对其进行 ZIP(压缩):
public Stream Compress(string folder)
{
try
{
var tempFile = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
ZipFile.CreateFromDirectory(folder, tempFile, CompressionLevel.Optimal, false);
return new Stream(tempFile);
}
catch (Exception e)
{
// handle exception
...
}
}
但是由于符号链接,我有以下例外:
System.IO.FileNotFoundException:找不到文件\'/tmp/2a765552-c60d-4ff8-b915-54e3d049902f/environment/bin/python3\'。
有没有办法忽视或者解决符号链接?
-
您使用的是什么 zip 实用程序?查看文档以了解如何处理符号链接。有很多 ZIP 实用程序,但并非都相同。
-
@jdweng 我正在使用 ZipFile 类。 docs.microsoft.com/en-us/dotnet/api/…
-
看起来 ZipFile 没有办法避免异常。在左侧的同一链接中,有 ZipArchive 和 ZipArchiveEntry,可用于一次添加一个文件以进行归档。
标签: c# .net-core zip symlink system.io.compression