Example #1
0
        public Task PutAsync(string targetFilename, string sourceFilePath, CancellationToken cancelToken)
        {
            string targetFilePath = GetRemoteName(targetFilename);

            if (m_moveFile)
            {
                if (systemIO.FileExists(targetFilePath))
                {
                    systemIO.FileDelete(targetFilePath);
                }

                var sourceFileInfo   = new FileInfo(sourceFilePath);
                var sourceFileLength = sourceFileInfo.Exists ? (long?)sourceFileInfo.Length : null;

                systemIO.FileMove(sourceFilePath, targetFilePath);
                if (m_verifyDestinationLength)
                {
                    VerifyMatchingSize(targetFilePath, null, sourceFileLength);
                }
            }
            else
            {
                systemIO.FileCopy(sourceFilePath, targetFilePath, true);
                if (m_verifyDestinationLength)
                {
                    VerifyMatchingSize(targetFilePath, sourceFilePath);
                }
            }

            return(Task.FromResult(true));
        }
Example #2
0
 /// <summary>
 /// Alternative to System.IO.Compression.ZipFile.ExtractToDirectory()
 /// that handles long paths.
 /// </summary>
 protected static void ZipFileExtractToDirectory(string sourceArchiveFileName, string destinationDirectoryName)
 {
     if (Platform.IsClientWindows)
     {
         // Handle long paths under Windows by extracting to a
         // temporary file and moving the resulting file to the
         // actual destination using functions that support
         // long paths.
         using (var archive = ZipFile.OpenRead(sourceArchiveFileName))
         {
             foreach (var entry in archive.Entries)
             {
                 // By the ZIP spec, directories end in a forward slash
                 var isDirectory = entry.FullName.EndsWith("/");
                 var destination =
                     systemIO.PathGetFullPath(systemIO.PathCombine(destinationDirectoryName, entry.FullName));
                 if (isDirectory)
                 {
                     systemIO.DirectoryCreate(destination);
                 }
                 else
                 {
                     // Not every directory is recorded separately,
                     // so create directories if needed
                     systemIO.DirectoryCreate(systemIO.PathGetDirectoryName(destination));
                     // Extract file to temporary file, then move to
                     // the (possibly) long path destination
                     var tempFile = Path.GetTempFileName();
                     try
                     {
                         entry.ExtractToFile(tempFile, true);
                         systemIO.FileMove(tempFile, destination);
                     }
                     finally
                     {
                         if (systemIO.FileExists(tempFile))
                         {
                             systemIO.FileDelete(tempFile);
                         }
                     }
                 }
             }
         }
     }
     else
     {
         ZipFile.ExtractToDirectory(sourceArchiveFileName, destinationDirectoryName);
     }
 }