UnauthorizedAccessException поймали при архивировании файла с использованием Ionic zip

Наш QA сообщил о следующей ошибке во время производства:

Access to the path "C: \ ProgramData \ avi \ Logs \ IMPMDesktopClient HTML Debug - Copy - Copy - Copy - Copy - Copy - Copy (2) - Copy.zip" was denied.
At System.IO.__ Error.WinIOError (Int32 errorCode, String maybeFullPath)
   In System.IO.FileStream.Init(String path, FileMode mode, FileAccessAccess, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptionsOptions, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
   At System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
   At Ionic.Zip.ZipEntry._WriteFileData(Stream s)
   At Ionic.Zip.ZipEntry.Write(Stream s)
   At Ionic.Zip.ZipFile.Save()
   At Ionic.Zip.ZipFile.Save(String fileName)
   At IMPMDesktopClient.LogUploader.ZipupLogsForPosting(String strFileTag)
   At IMPMDesktopClient.LogUploader.UploadLogs(TimeSpan timeout, String strTag)

Я пытался повторить дело, но не смог этого сделать. Он успешно работает на моей машине.

В каталоге есть папки: Logs и Temp: C:\ProgramData\avi. Программа копирует и архивирует папку Log и помещает ее в Temp. Если размер сжатой папки превышает 4 МБ (скажем, 500 МБ), он разделяет ZIP-файл на несколько кусков меньших ZIP-файлов размером более или менее 4 МБ.

Вот мой код: Пожалуйста, дайте мне знать, где я могу пойти не так.

Примечание: я использую библиотеку Ionic zip.

private static string ZipupLogsForPosting(string strFileTag)
{
    string strDstPath = Updater.UpdateFolder; 
    string strZipFileName = string.Format("{0}_{1}_{2}_Logs.zip",
                                           Environment.MachineName,
                                           Environment.UserName,
                                           strFileTag.Substring(0, Math.Min(strFileTag.Length, 20)));

    var sb = new StringBuilder(strZipFileName);
    sb.RemoveTheseChars(Path.GetInvalidFileNameChars());
    strZipFileName = sb.ToString();

    string strZipPath = Path.Combine(strDstPath, strZipFileName);

    if (File.Exists(strZipPath))
    {
        if ((File.GetAttributes(strZipPath) & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
        {
            File.SetAttributes(strZipPath, FileAttributes.Normal);
        }
        File.Delete(strZipPath);
    }

    Log.Trace("Zipping up logs for posting, Tag='{0}'", strFileTag);
    Log.FlushAllLogs();

    using (var zip = new ZipFile())
    {
        zip.AddDirectory(Log.LogsPath);
        zip.Save(strZipPath);
    }

    return (strZipPath);
}

Примечание. Пожалуйста, не беспокойтесь о разделении папок на молнии. Проблема возникает при попытке заархивировать папку в начале до разделения.

0 ответов

Другие вопросы по тегам