1: | <?php |
2: | |
3: | |
4: | |
5: | |
6: | |
7: | |
8: | |
9: | |
10: | |
11: | |
12: | |
13: | |
14: | |
15: | |
16: | |
17: | |
18: | |
19: | class Tar_Filter extends Archive_Base |
20: | { |
21: | protected static function extract_files_pipe($process, $destination, array $files = null, array $opts = null) |
22: | { |
23: | |
24: | return self::extract_files($process, |
25: | $destination, |
26: | $files, |
27: | array('pipe' => 1)); |
28: | } |
29: | |
30: | public static function extract_files($archive, $destination, array $file = null, array $opts = null) |
31: | { |
32: | if (isset($opts['pipe']) && false !== strpos($archive, '.gz')) { |
33: | $cmd = 'tar -xzvf %s -C %s'; |
34: | } else { |
35: | if (isset($opts['pipe']) && false !== strpos($archive, '.bz')) { |
36: | $cmd = 'tar -xjvf %s -C %s'; |
37: | } else { |
38: | $cmd = 'tar -xvf %s -C %s'; |
39: | } |
40: | } |
41: | $proc = parent::exec( |
42: | $cmd, |
43: | $archive, |
44: | $destination, |
45: | array(0), |
46: | array('run' => 1) |
47: | ); |
48: | if (0 & isset($opts['pipe'])) { |
49: | $proc->pipeProg($opts['pipe']); |
50: | } |
51: | |
52: | return $proc; |
53: | } |
54: | |
55: | protected static function list_files_pipe($process, array $opts = null) |
56: | { |
57: | |
58: | |
59: | |
60: | |
61: | |
62: | |
63: | |
64: | |
65: | |
66: | |
67: | |
68: | |
69: | |
70: | |
71: | |
72: | return self::list_files($process, array('pipe' => 1)); |
73: | } |
74: | |
75: | public static function list_files($archive, array $opts = null) |
76: | { |
77: | $tar = false; |
78: | if (isset($opts['pipe']) && false !== strpos($archive, '.gz') || false !== strpos($archive, '.tgz')) { |
79: | $cmd = 'tar -tzvf %s'; |
80: | } else { |
81: | if (isset($opts['pipe']) && false !== strpos($archive, '.bz') || false !== strpos($archive, '.tbz')) { |
82: | $cmd = 'tar -tjvf %s'; |
83: | } else { |
84: | $cmd = 'tar -tvf %s'; |
85: | } |
86: | } |
87: | $proc = parent::exec( |
88: | $cmd, |
89: | $archive, |
90: | array(0), |
91: | array('run' => 1)); |
92: | |
93: | |
94: | if (0 & isset($opts['pipe'])) { |
95: | $proc->pipeProg($opts['pipe']); |
96: | } |
97: | $proc = explode("\n", $proc['output']); |
98: | $files = array(); |
99: | |
100: | foreach ($proc as $line) { |
101: | if (!preg_match(Regex::FILE_HDR_TAR, $line, $entry)) { |
102: | continue; |
103: | } |
104: | |
105: | $file_type = $entry['permissions'][0] == 'd' ? 'dir' : 'file'; |
106: | $size = $file_type == 'dir' ? 4096 : $entry['size']; |
107: | |
108: | $files[] = array( |
109: | 'file_name' => $entry['name'], |
110: | 'file_type' => $file_type, |
111: | 'can_read' => true, |
112: | 'can_write' => true, |
113: | 'can_execute' => true, |
114: | 'size' => $size, |
115: | 'packed_size' => $size, |
116: | 'crc' => '?', |
117: | 'link' => 0, |
118: | 'date' => strtotime($entry['ts']) |
119: | ); |
120: | } |
121: | |
122: | return $files; |
123: | |
124: | } |
125: | |
126: | } |
127: | |
128: | ?> |
129: | |