@@ -55,6 +55,9 @@ public class ArchiveEntry
55
55
56
56
private final int mode ;
57
57
58
+ private final int defaultDirMode ; // Sometimes a directory needs to be created. Which mode should it be ?
59
+ // this mode is at the time of the creation of the archive entry, which is an important distinction
60
+
58
61
private PlexusIoResourceAttributes attributes ;
59
62
60
63
/**
@@ -64,12 +67,14 @@ public class ArchiveEntry
64
67
* @param type FILE or DIRECTORY
65
68
* @param mode octal unix style permissions
66
69
* @param collection
70
+ * @param defaultDirMode
67
71
*/
68
72
private ArchiveEntry ( String name , @ Nonnull PlexusIoResource resource , int type , int mode ,
69
- PlexusIoResourceCollection collection )
73
+ PlexusIoResourceCollection collection , int defaultDirMode )
70
74
{
71
75
this .name = name ;
72
76
this .collection = collection ;
77
+ this .defaultDirMode = defaultDirMode ;
73
78
try {
74
79
this .resource = collection != null ? collection .resolve (resource ) : resource ;
75
80
} catch (IOException e ) {
@@ -151,18 +156,18 @@ public int getMode()
151
156
}
152
157
153
158
public static ArchiveEntry createFileEntry ( String target , PlexusIoResource resource , int permissions ,
154
- PlexusIoResourceCollection collection )
159
+ PlexusIoResourceCollection collection , int defaultDirectoryPermissions )
155
160
throws ArchiverException
156
161
{
157
162
if ( resource .isDirectory () )
158
163
{
159
164
throw new ArchiverException ( "Not a file: " + resource .getName () );
160
165
}
161
166
final int type = resource .isSymbolicLink () ? SYMLINK : FILE ;
162
- return new ArchiveEntry ( target , resource , type , permissions , collection );
167
+ return new ArchiveEntry ( target , resource , type , permissions , collection , defaultDirectoryPermissions );
163
168
}
164
169
165
- public static ArchiveEntry createFileEntry ( String target , File file , int permissions )
170
+ public static ArchiveEntry createFileEntry ( String target , File file , int permissions , int defaultDirectoryPermissions )
166
171
throws ArchiverException
167
172
{
168
173
if ( !file .isFile () )
@@ -181,21 +186,23 @@ public static ArchiveEntry createFileEntry( String target, File file, int permis
181
186
}
182
187
183
188
final PlexusIoFileResource res = PlexusIoFileResource .justAFile ( file , attrs );
184
- return new ArchiveEntry ( target , res , FILE , permissions , null );
189
+ return new ArchiveEntry ( target , res , FILE , permissions , null , defaultDirectoryPermissions );
185
190
}
186
191
187
- public static ArchiveEntry createDirectoryEntry ( String target , @ Nonnull PlexusIoResource resource , int permissions )
192
+ public static ArchiveEntry createDirectoryEntry ( String target , @ Nonnull PlexusIoResource resource , int permissions ,
193
+ int defaultDirectoryPermissions )
188
194
throws ArchiverException
189
195
{
190
196
if ( !resource .isDirectory () )
191
197
{
192
198
throw new ArchiverException ( "Not a directory: " + resource .getName () );
193
199
}
194
200
final int type = resource .isSymbolicLink () ? SYMLINK : DIRECTORY ;
195
- return new ArchiveEntry ( target , resource , type , permissions , null );
201
+ return new ArchiveEntry ( target , resource , type , permissions , null , defaultDirectoryPermissions );
196
202
}
197
203
198
- public static ArchiveEntry createDirectoryEntry ( String target , final File file , int permissions )
204
+ public static ArchiveEntry createDirectoryEntry ( String target , final File file , int permissions ,
205
+ int defaultDirMode1 )
199
206
throws ArchiverException
200
207
{
201
208
if ( !file .isDirectory () )
@@ -204,31 +211,33 @@ public static ArchiveEntry createDirectoryEntry( String target, final File file,
204
211
}
205
212
206
213
final PlexusIoFileResource res = new PlexusIoFileResource ( file , ArchiverAttributeUtils .getFileAttributes (file ));
207
- return new ArchiveEntry ( target , res , DIRECTORY , permissions , null );
214
+ return new ArchiveEntry ( target , res , DIRECTORY , permissions , null , defaultDirMode1 );
208
215
}
209
216
210
- public static ArchiveEntry createEntry ( String target , File file , int filePerm , int dirPerm )
217
+ public static ArchiveEntry createEntry ( String target , File file , int filePerm , int dirPerm , int defaultDirectoryPermissions )
211
218
throws ArchiverException
212
219
{
213
220
if ( file .isDirectory () )
214
221
{
215
- return createDirectoryEntry ( target , file , dirPerm );
222
+ return createDirectoryEntry ( target , file , dirPerm , defaultDirectoryPermissions );
216
223
}
217
224
else if ( file .isFile () )
218
225
{
219
- return createFileEntry ( target , file , filePerm );
226
+ return createFileEntry ( target , file , filePerm , defaultDirectoryPermissions );
220
227
}
221
228
else // FIXME: handle symlinks?
222
229
{
223
230
throw new ArchiverException ( "Neither a file nor a directory: " + file );
224
231
}
225
232
}
226
233
227
- public static ArchiveEntry createSymlinkEntry (String symlinkName , int permissions , String symlinkDestination )
234
+ public static ArchiveEntry createSymlinkEntry ( String symlinkName , int permissions , String symlinkDestination ,
235
+ int defaultDirectoryPermissions
236
+ )
228
237
{
229
238
File symlinkFile = new File (symlinkName );
230
239
final ArchiveEntry archiveEntry = new ArchiveEntry (symlinkName , new PlexusIoVirtualSymlinkResource (symlinkFile , symlinkDestination ), SYMLINK , permissions ,
231
- null );
240
+ null , defaultDirectoryPermissions );
232
241
return archiveEntry ;
233
242
}
234
243
@@ -246,4 +255,9 @@ public void setResourceAttributes( PlexusIoResourceAttributes attributes )
246
255
{
247
256
return resource ;
248
257
}
258
+
259
+ public int getDefaultDirMode ()
260
+ {
261
+ return defaultDirMode ;
262
+ }
249
263
}
0 commit comments