Ejemplo n.º 1
0
        private void processTask(RestoreTask task)
        {
            Logger.Debug("StorageThread:processTask:RestoreTask");
            Stream         inStream   = File.OpenRead(task.ArchivePath);
            Stream         gzipStream = new GZipInputStream(inStream);
            TarInputStream tarStream  = new TarInputStream(gzipStream);
            TarEntry       entry;
            List <string>  list    = task.RelativeFilenames();
            RecoverResult  recover = new RecoverResult(task.OutputDir, true);

            while ((entry = tarStream.GetNextEntry()) != null)
            {
                if (entry.IsDirectory)
                {
                    continue;
                }
                if (list.IndexOf(entry.Name) != -1)
                {
                    string name = entry.Name.Replace('/', Path.DirectorySeparatorChar);
                    name = Path.Combine(task.OutputDir, name);
                    Directory.CreateDirectory(Path.GetDirectoryName(name));
                    FileStream outStream = new FileStream(name, FileMode.CreateNew);
                    tarStream.CopyEntryContents(outStream);
                    outStream.Close();
                    DateTime myDt = DateTime.SpecifyKind(entry.ModTime, DateTimeKind.Utc);
                    File.SetLastWriteTime(name, myDt);
                }
            }
            tarStream.Close();
            lock (_lock)
            {
                recoverResults.Enqueue(recover);
            }
        }
Ejemplo n.º 2
0
 public static void testUnTarGZip()
 {
     Logger.init(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\temp\\scratch 2\\uncompress.log");
     Guid myGuid = Guid.NewGuid();
     string archivePath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\temp\\scratch 2\\01010101-0101-0101-0101-010101010101_123_0.tgz";
     string outputDir = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\temp\\scratch 2";
     RestoreTask rt = new RestoreTask(archivePath, outputDir);
     rt.Add("cs 410 2012-12-09\\echo backup logo v1.png");
     StorageThread st = new StorageThread("", myGuid);
     st.EnqueueStorageTask(rt);
     Print("added task to storagethread");
     int x=0;
     while (st.IsWorking())
     {
         x++;
         Thread.Sleep(1000);
         Print("waiting for storagethread to finish working " + x);
     }
     Print("storagethread done");
     st.RequestStop();
     Print("requested stop of storagethread");
     while (st.IsAlive())
     {
         x++;
         Thread.Sleep(1000);
         Print("waiting for storagethread to stop " + x);
     }
     Print("storagethread stopped");
     Console.WriteLine("press a key to continue");
     Console.ReadKey();
 }
Ejemplo n.º 3
0
 private void processTask(RestoreTask task)
 {
     Logger.Debug("StorageThread:processTask:RestoreTask");
     Stream inStream = File.OpenRead(task.ArchivePath);
     Stream gzipStream = new GZipInputStream(inStream);
     TarInputStream tarStream = new TarInputStream(gzipStream);
     TarEntry entry;
     List<string> list = task.RelativeFilenames();
     RecoverResult recover = new RecoverResult(task.OutputDir, true);
     while ((entry = tarStream.GetNextEntry()) != null)
     {
         if (entry.IsDirectory) continue;
         if (list.IndexOf(entry.Name) != -1)
         {
             string name = entry.Name.Replace('/', Path.DirectorySeparatorChar);
             name = Path.Combine(task.OutputDir, name);
             Directory.CreateDirectory(Path.GetDirectoryName(name));
             FileStream outStream = new FileStream(name, FileMode.CreateNew);
             tarStream.CopyEntryContents(outStream);
             outStream.Close();
             DateTime myDt = DateTime.SpecifyKind(entry.ModTime, DateTimeKind.Utc);
             File.SetLastWriteTime(name, myDt);
         }
     }
     tarStream.Close();
     lock (_lock)
     {
         recoverResults.Enqueue(recover);
     }
 }