2
Vote

Possible bug in ZlpDirectoryInfo.LastWriteTime setter

description

Thanks for a really useful project, I'm really pleased with Zeta Long Paths.

However, I run into a possible bug.

The setter for ZlpDirectoryInfo.LastWriteTime will end up in calling System.IO.File.SetLastWriteTime instead of System.IO.Directory.SetLastWriteTime, which throws UnauthorizedAccessException (but it's a bogus error, calling System.IO.DirectoryInfo.LastWriteTime setter works fine for the same directory.

Code to reproduce:
namespace LongPathTest
{
    class Program
    {
        static void Main(string[] args)
        {
            // Generate a unique directory name and create it on disk
            var dir = System.IO.Path.Combine(System.IO.Path.GetTempPath(), System.Guid.NewGuid().ToString("b"));
            System.IO.Directory.CreateDirectory(dir);

            System.Console.WriteLine("Creating dir " + dir);
            try
            {
                // Create an instance of ZlpDirectoryInfo for the new directory
                var dirInfo = new ZetaLongPaths.ZlpDirectoryInfo(dir);
                System.Console.WriteLine("Updating LastWriteTime for: " + dir);

                // Attempt to update LastWriteTime
                //
                // BUG: ZlpDirectoryInfo.LastWriteTime will call ZlpIOHelper.SetFileLastWriteTime, which
                // in turn will call "System.IO.File.SetLastWriteTime(filePath, date);" since this is
                // a "short" path.
                dirInfo.LastWriteTime = System.DateTime.Now;

                // One possible fix would be to call "System.IO.Directory.SetLastWriteTime" instead
                // if SetFileLastWriteTime gets called with a directory path.

                // The above code will never get called because of the bug
                System.Console.WriteLine("Successfully updated LastWriteTime for: " + dir);
            }
            catch (System.Exception exception)
            {
                System.Console.WriteLine("Failed to updated LastWriteTime, reason: " + exception.Message);
            }
        }
    }
}

comments