︙ | | | ︙ | |
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
* LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
* file.
*/
#include "config.h"
#import "OFApplication.h"
#import "OFFileManager.h"
#import "OFStdIOStream.h"
#import "OFLocale.h"
#import "GZIPArchive.h"
#import "OFArc.h"
static OFArc *app;
static void
setPermissions(OFString *destination, OFString *source)
{
#ifdef OF_FILE_MANAGER_SUPPORTS_PERMISSIONS
OFFileManager *fileManager = [OFFileManager defaultManager];
OFFileAttributes attributes = [fileManager
attributesOfItemAtPath: source];
OFFileAttributeKey key = OFFilePOSIXPermissions;
OFFileAttributes destinationAttributes = [OFDictionary
dictionaryWithObject: [attributes objectForKey: key]
forKey: key];
[fileManager setAttributes: destinationAttributes
ofItemAtPath: destination];
|
>
>
|
>
|
|
|
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
* LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
* file.
*/
#include "config.h"
#import "OFApplication.h"
#import "OFArray.h"
#import "OFFile.h"
#import "OFFileManager.h"
#import "OFIRI.h"
#import "OFLocale.h"
#import "OFStdIOStream.h"
#import "GZIPArchive.h"
#import "OFArc.h"
static OFArc *app;
static void
setPermissions(OFString *destination, OFIRI *source)
{
#ifdef OF_FILE_MANAGER_SUPPORTS_PERMISSIONS
OFFileManager *fileManager = [OFFileManager defaultManager];
OFFileAttributes attributes = [fileManager
attributesOfItemAtIRI: source];
OFFileAttributeKey key = OFFilePOSIXPermissions;
OFFileAttributes destinationAttributes = [OFDictionary
dictionaryWithObject: [attributes objectForKey: key]
forKey: key];
[fileManager setAttributes: destinationAttributes
ofItemAtPath: destination];
|
︙ | | | ︙ | |
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
@implementation GZIPArchive
+ (void)initialize
{
if (self == [GZIPArchive class])
app = (OFArc *)[OFApplication sharedApplication].delegate;
}
+ (instancetype)archiveWithPath: (OFString *)path
stream: (OF_KINDOF(OFStream *))stream
mode: (OFString *)mode
encoding: (OFStringEncoding)encoding
{
return [[[self alloc] initWithPath: path
stream: stream
mode: mode
encoding: encoding] autorelease];
}
- (instancetype)initWithPath: (OFString *)path
stream: (OF_KINDOF(OFStream *))stream
mode: (OFString *)mode
encoding: (OFStringEncoding)encoding
{
self = [super init];
@try {
_stream = [[OFGZIPStream alloc] initWithStream: stream
mode: mode];
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
- (void)dealloc
{
[_stream release];
[super dealloc];
}
- (void)listFiles
{
[OFStdErr writeLine: OF_LOCALIZED(@"cannot_list_gz",
|
|
|
|
|
|
|
|
|
|
|
|
|
>
>
|
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
@implementation GZIPArchive
+ (void)initialize
{
if (self == [GZIPArchive class])
app = (OFArc *)[OFApplication sharedApplication].delegate;
}
+ (instancetype)archiveWithIRI: (OFIRI *)IRI
stream: (OF_KINDOF(OFStream *))stream
mode: (OFString *)mode
encoding: (OFStringEncoding)encoding
{
return [[[self alloc] initWithIRI: IRI
stream: stream
mode: mode
encoding: encoding] autorelease];
}
- (instancetype)initWithIRI: (OFIRI *)IRI
stream: (OF_KINDOF(OFStream *))stream
mode: (OFString *)mode
encoding: (OFStringEncoding)encoding
{
self = [super init];
@try {
_stream = [[OFGZIPStream alloc] initWithStream: stream
mode: mode];
_archiveIRI = [IRI copy];
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
- (void)dealloc
{
[_stream release];
[_archiveIRI release];
[super dealloc];
}
- (void)listFiles
{
[OFStdErr writeLine: OF_LOCALIZED(@"cannot_list_gz",
|
︙ | | | ︙ | |
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
[OFStdErr writeLine: OF_LOCALIZED(
@"cannot_extract_specific_file_from_gz",
@"Cannot extract a specific file of a .gz archive!")];
app->_exitStatus = 1;
return;
}
fileName = app->_archivePath.lastPathComponent
.stringByDeletingPathExtension;
if (app->_outputLevel >= 0)
[OFStdOut writeString: OF_LOCALIZED(@"extracting_file",
@"Extracting %[file]...",
@"file", fileName)];
if (![app shouldExtractFile: fileName outFileName: fileName])
return;
output = [OFFile fileWithPath: fileName mode: @"w"];
setPermissions(fileName, app->_archivePath);
while (!_stream.atEndOfStream) {
ssize_t length = [app copyBlockFromStream: _stream
toStream: output
fileName: fileName];
if (length < 0) {
|
|
|
|
|
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
[OFStdErr writeLine: OF_LOCALIZED(
@"cannot_extract_specific_file_from_gz",
@"Cannot extract a specific file of a .gz archive!")];
app->_exitStatus = 1;
return;
}
/* FIXME: Should use IRI-specific path extension deletion. */
fileName = _archiveIRI.lastPathComponent.stringByDeletingPathExtension;
if (app->_outputLevel >= 0)
[OFStdOut writeString: OF_LOCALIZED(@"extracting_file",
@"Extracting %[file]...",
@"file", fileName)];
if (![app shouldExtractFile: fileName outFileName: fileName])
return;
output = [OFFile fileWithPath: fileName mode: @"w"];
setPermissions(fileName, _archiveIRI);
while (!_stream.atEndOfStream) {
ssize_t length = [app copyBlockFromStream: _stream
toStream: output
fileName: fileName];
if (length < 0) {
|
︙ | | | ︙ | |
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
|
@"Extracting %[file]... done",
@"file", fileName)];
}
}
- (void)printFiles: (OFArray OF_GENERIC(OFString *) *)files
{
OFString *fileName = app->_archivePath.lastPathComponent
.stringByDeletingPathExtension;
if (files.count > 0) {
[OFStdErr writeLine: OF_LOCALIZED(
@"cannot_print_specific_file_from_gz",
@"Cannot print a specific file of a .gz archive!")];
app->_exitStatus = 1;
|
>
|
|
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
@"Extracting %[file]... done",
@"file", fileName)];
}
}
- (void)printFiles: (OFArray OF_GENERIC(OFString *) *)files
{
/* FIXME: Should use IRI-specific path extension deletion. */
OFString *fileName = _archiveIRI.lastPathComponent
.stringByDeletingPathExtension;
if (files.count > 0) {
[OFStdErr writeLine: OF_LOCALIZED(
@"cannot_print_specific_file_from_gz",
@"Cannot print a specific file of a .gz archive!")];
app->_exitStatus = 1;
|
︙ | | | ︙ | |