diff --git a/wbackup/ArchiveTarFile.cs b/wbackup/ArchiveTarFile.cs index c339e61..1534eb5 100644 --- a/wbackup/ArchiveTarFile.cs +++ b/wbackup/ArchiveTarFile.cs @@ -23,25 +23,28 @@ protected int buffSize; protected byte[][] readBuffer; protected DateTime minLastWriteDate; + protected bool clearArchiveFlags; - public ArchiveTarFile(string exportPath, BackupStreamBase stream = null):base(stream) + public ArchiveTarFile(string exportPath, bool clearArchiveFlags, BackupStreamBase stream = null):base(stream) { string zipFileName = exportPath + ".tar.gz"; + this.clearArchiveFlags = clearArchiveFlags; + // 出力先ストリームのインスタンス生成 - fileOutputStream = new FileStream(zipFileName, FileMode.Create, FileAccess.Write); - gzipOutputStream = new GZipOutputStream(fileOutputStream); - tarOutputStream = new TarOutputStream(gzipOutputStream, Encoding.UTF8); - gzipOutputStream.IsStreamOwner = false; + this.fileOutputStream = new FileStream(zipFileName, FileMode.Create, FileAccess.Write); + this.gzipOutputStream = new GZipOutputStream(fileOutputStream); + this.tarOutputStream = new TarOutputStream(gzipOutputStream, Encoding.UTF8); + this.gzipOutputStream.IsStreamOwner = false; // ソース読込のためのバッファ生成 - buffSelect = 0; - buffSize = tarOutputStream.RecordSize; - readBuffer = new byte[2][]; - readBuffer[0] = new byte[buffSize]; - readBuffer[1] = new byte[buffSize]; + this.buffSelect = 0; + this.buffSize = tarOutputStream.RecordSize; + this.readBuffer = new byte[2][]; + this.readBuffer[0] = new byte[buffSize]; + this.readBuffer[1] = new byte[buffSize]; - archiveCount = 0; + this.archiveCount = 0; minLastWriteDate = DateTime.Parse("1970-12-01"); } @@ -90,6 +93,16 @@ AddNextSource(sourceFileName); } + + if (this.clearArchiveFlags) + { + var attributes = File.GetAttributes(sourceFileName); + if (attributes.HasFlag(FileAttributes.Archive)) + { + attributes = attributes & ~FileAttributes.Archive; + File.SetAttributes(sourceFileName, attributes); + } + } } } } diff --git a/wbackup/ClearArchiveFlag.cs b/wbackup/ClearArchiveFlag.cs deleted file mode 100644 index e11b7d3..0000000 --- a/wbackup/ClearArchiveFlag.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.IO; -using System.Threading; -using System.Threading.Tasks; - -namespace wbackup -{ - class ClearArchiveFlag : BackupStreamBase - { - protected int archiveCount; - - public ClearArchiveFlag(BackupStreamBase stream = null) : base(stream) - { - archiveCount = 0; - } - - protected override void DoWork(string sourceFileName) - { - if (log.IsDebugEnabled) log.DebugFormat("Clear {0}, {1}", Interlocked.Increment(ref archiveCount), sourceFileName); - - var attributes = File.GetAttributes(sourceFileName); - if (attributes.HasFlag(FileAttributes.Archive)) - { - attributes = attributes & ~FileAttributes.Archive; - File.SetAttributes(sourceFileName, attributes); - } - } - } -} diff --git a/wbackup/ParallelBackup.cs b/wbackup/ParallelBackup.cs index 721cdcb..4afcf6d 100644 --- a/wbackup/ParallelBackup.cs +++ b/wbackup/ParallelBackup.cs @@ -48,12 +48,12 @@ public override void Wait() { - base.Wait(); - foreach (var next in nextParallelStream) { next.Wait(); } + + base.Wait(); } protected override void OnEndStream() diff --git a/wbackup/Program.cs b/wbackup/Program.cs index 37bb285..243bc35 100644 --- a/wbackup/Program.cs +++ b/wbackup/Program.cs @@ -37,7 +37,14 @@ for (int i = 0; i < param.maxThreadCount; i++) { string exportFileName = param.destinationDir + "-" + postFixString + "-" + i.ToString("00"); - parallel.AddNextStream(new ArchiveTarFile(exportFileName, new ClearArchiveFlag())); + if (param.backupMode == BackupMopde.Incremental) + { + parallel.AddNextStream(new ArchiveTarFile(exportFileName, false)); + } + else + { + parallel.AddNextStream(new ArchiveTarFile(exportFileName, true)); + } } // バックアップエンジンのインスタンスを生成する