1

I know here is some questions about this error in DotNetZip, I've tried all solutions and failed. I'm developing code on my Win8.1 notebook and have no problems, problems begin after deploy to the remote Win2008R2 server...

Here is the problem method:

public bool CreateZIP(string ListStep)
{
    Logger logger = LogManager.GetLogger("Task:CreateZIP" + this.TaskGuid);

    using (ZipFile zip = new ZipFile())
    {
        zip.AlternateEncoding = System.Text.Encoding.GetEncoding("cp866");
        zip.AlternateEncodingUsage = Ionic.Zip.ZipOption.Always;

        ...
        zip.AddFile(...) loop
        ...

        zip.MaxOutputSegmentSize = Properties.Settings.Default.ZIPSizeLimit * 1024 * 1024;

        string zipFolder = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"zip-tmp");
        string TaskZipFolder = Path.Combine(zipFolder, this.TaskGuid);

        try
        {
            if (!Directory.Exists(zipFolder)) Directory.CreateDirectory(zipFolder);
            if (!Directory.Exists(TaskZipFolder)) Directory.CreateDirectory(TaskZipFolder);

            zip.TempFileFolder = Path.GetTempPath();
            zip.Save(Path.Combine(TaskZipFolder, this.TaskGuid + @".zip"));
        }
        catch (Exception e)
        {
            logger.Fatal("Unable to save ZIP into ({0}): {1}", Path.Combine(TaskZipFolder, this.TaskGuid + @".zip"), e.ToString());
            throw;
        }
    }
    return true;
}

This code is running on remote server from domain user gfo-svc from C:\Courier\WD directory. Each object instance has it's GUID, for example e1664582-1bbc-4a9f-a9fe-e7ce4a0a8a55 So the zipFolder variable value is C:\Courier\WD\zip-tmp and TaskZipFolder value is C:\Courier\WD\zip-tmp\e1664582-1bbc-4a9f-a9fe-e7ce4a0a8a55

When this code tries to run it fails with this stack trace:

Unable to save ZIP into (C:\Courier\WD\zip-tmp\e1664582-1bbc-4a9f-a9fe-e7ce4a0a8a55\e1664582-1bbc-4a9f-a9fe-e7ce4a0a8a55.zip): System.UnauthorizedAccessException: Access to the path is denied.
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.__Error.WinIOError()
   at System.IO.File.InternalMove(String sourceFileName, String destFileName, Boolean checkHost)
   at Ionic.Zip.ZipSegmentedStream.TruncateBackward(UInt32 diskNumber, Int64 offset)
   at Ionic.Zip.ZipEntry.Write(Stream s)
   at Ionic.Zip.ZipFile.Save()
   at Ionic.Zip.ZipFile.Save(String fileName)
   at Worker.Task.CreateZIP(String ListStep) in Worker.cs:line 844

Line 844 contains this code: zip.Save(Path.Combine(TaskZipFolder, this.TaskGuid + @".zip"));

But in the C:\Courier\WD\zip-tmp\e1664582-1bbc-4a9f-a9fe-e7ce4a0a8a55 folder I can see file e1664582-1bbc-4a9f-a9fe-e7ce4a0a8a55.z01, so the first part of archive was saved before failure.

gfo-svc user has ownership on C:\Courier\WD directory and my code could create zip-tmp directory if it is not exists, and GUID-named directory in it. So the problem is not in Windows Security permissions. UAC on this remote server is disabled.

What could I do wrong? What might be wrong with my environment? What could I do?

insane
  • 45
  • 2
  • 8
  • "So the problem is not in Windows Security permissions." The message says otherwise. Simplify the testcase to `File.WriteAllText(path, "")`. This has nothing to do with zip.; Use procmon on the server to observe the exact failure as returned by the Windows Kernel. It will probably say ACCESS_DENIED or something. – usr Mar 11 '14 at 07:48
  • @usr `File.WriteAllText()` worked fine with no errors. In procmon there is one ACESS_DENIED message, but I can't understand where it comes from... – insane Mar 11 '14 at 10:57
  • Well, what does the path next to ACCESS_DENIED say? Is it the exact zip file path? – usr Mar 11 '14 at 12:00
  • Note, that the error occured when `File.InternalMove` was running. THe zip lib moved the file. Maybe destination access was denied. – usr Mar 11 '14 at 12:02
  • @usr this is what procmon says about ACCESS DENIED message: `Date & Time: 3/11/2014 4:40:41 PM Event Class: File System Operation: CreateFile Result: ACCESS DENIED Path: C:\Windows\SysWOW64 TID: 3388 Duration: 0.0000260 Desired Access: Write Data/Add File, Synchronize Disposition: Open Options: Attributes: n/a ShareMode: Read, Write AllocationSize: n/a` – insane Mar 11 '14 at 12:38
  • What about the accesses to the zip file and temp path? Are they all SUCCESS? – usr Mar 11 '14 at 12:53

1 Answers1

2

Ok, here is the reason: This code runs twice on the same host: first time manually from cmd and second time from Windows Task Scheduler. By default, Task Scheduler starts tasks from C:\windows\system32 and process could not write into it. But my code tried to write into relative to working directory path, so in fact it was trying to write into ...\system32\tmp-dir.

insane
  • 45
  • 2
  • 8