2 using System
.Collections
;
6 using ICSharpCode
.SharpZipLib
;
7 using ICSharpCode
.SharpZipLib
.Tar
;
14 // FIXME: When we untar (using the command-line 'tar') one of the
15 // files created by this class, it always complains about 'A lone zero
16 // block at xxx'. Are we doing something wrong, or is SharpZipLib the
19 public class TarFileObject
: FileObject
{
21 public TarFileObject (DirectoryObject tar_root
)
25 ArrayList to_be_tarred
;
26 to_be_tarred
= new ArrayList (tar_root
.Children
);
28 foreach (FileSystemObject fso
in to_be_tarred
) {
29 tar_root
.RemoveChild (fso
, null);
30 this.AddChild (fso
, null);
34 override protected string GetChildUri (FileSystemObject children
)
36 // FIXME: What is the uri scheme for tar files?
37 return this.Uri
+ "#" + children
.Name
;
40 override public string MimeType
{
41 get { return "application/x-tar"; }
44 override public string Extension
{
45 get { return ".tar"; }
48 private void WriteObjectToTar (TarOutputStream tar_out
,
52 MemoryStream memory
= null;
55 header
= new TarHeader ();
57 StringBuilder name_builder
;
58 name_builder
= new StringBuilder (fso
.FullName
);
59 name_builder
.Remove (0, this.FullName
.Length
+1);
60 header
.name
= name_builder
;
62 header
.modTime
= fso
.Timestamp
;
63 if (fso
is DirectoryObject
) {
64 header
.mode
= 511; // 0777
65 header
.typeFlag
= TarHeader
.LF_DIR
;
68 header
.mode
= 438; // 0666
69 header
.typeFlag
= TarHeader
.LF_NORMAL
;
70 memory
= new MemoryStream ();
71 ((FileObject
) fso
).AddToStream (memory
, tracker
);
72 header
.size
= memory
.Length
;
76 entry
= new TarEntry (header
);
78 tar_out
.PutNextEntry (entry
);
80 tar_out
.Write (memory
.ToArray (), 0, (int) memory
.Length
);
83 tar_out
.CloseEntry ();
85 // If this is a directory, write out the children
86 if (fso
is DirectoryObject
)
87 foreach (FileSystemObject child
in fso
.Children
)
88 WriteObjectToTar (tar_out
, child
, tracker
);
91 override public void AddToStream (Stream stream
, EventTracker tracker
)
94 tracker
.ExpectingAdded (this.Uri
);
96 UnclosableStream unclosable
;
97 unclosable
= new UnclosableStream (stream
);
99 TarOutputStream tar_out
;
100 tar_out
= new TarOutputStream (unclosable
);
101 foreach (FileSystemObject fso
in Children
)
102 WriteObjectToTar (tar_out
, fso
, tracker
);
104 // This calls close on the underlying stream,
105 // which is why we wrapped the stream in an
110 override protected bool MatchesQueryPart (QueryPart part
)
112 // The only thing that could match is the name, and we check
113 // for that already in FileSystemObject.MatchesQuery.