@@ -93,27 +93,28 @@ public SMB2CreateResponseContext apply(SmbPath target) {
9393 return new SMB2CreateResponseContext (resp , path , this );
9494 } catch (PathResolveException e ) {
9595 throw new SMBApiException (e .getStatusCode (), SMB2MessageCommandCode .SMB2_CREATE ,
96- "Cannot resolve path " + path , e );
96+ "Cannot resolve path " + path , e );
9797 }
9898 }
9999
100100 private SMB2CreateResponseContext resolveAndCreateFile (final SmbPath path ,
101- final SMB2ImpersonationLevel impersonationLevel , final Set <AccessMask > accessMask ,
102- final Set <FileAttributes > fileAttributes , final Set <SMB2ShareAccess > shareAccess ,
103- final SMB2CreateDisposition createDisposition , final Set <SMB2CreateOptions > createOptions ) {
101+ final SMB2ImpersonationLevel impersonationLevel , final Set <AccessMask > accessMask ,
102+ final Set <FileAttributes > fileAttributes , final Set <SMB2ShareAccess > shareAccess ,
103+ final SMB2CreateDisposition createDisposition , final Set <SMB2CreateOptions > createOptions ) {
104104 try {
105- SMB2CreateResponseContext target = resolver .resolve (session , path , new PathResolver .ResolveAction <SMB2CreateResponseContext >(){
105+ SMB2CreateResponseContext target = resolver .resolve (session , path , new PathResolver .ResolveAction <SMB2CreateResponseContext >() {
106106 @ Override
107107 public SMB2CreateResponseContext apply (SmbPath target ) {
108108 DiskShare resolvedShare = rerouteIfNeeded (path , target );
109109 return resolvedShare .createFileAndResolve (target , impersonationLevel , accessMask , fileAttributes ,
110- shareAccess , createDisposition , createOptions ); }
110+ shareAccess , createDisposition , createOptions );
111+ }
111112 });
112113
113114 return target ;
114115 } catch (PathResolveException pre ) {
115116 throw new SMBApiException (pre .getStatus ().getValue (), SMB2MessageCommandCode .SMB2_CREATE ,
116- "Cannot resolve path " + path , pre );
117+ "Cannot resolve path " + path , pre );
117118 }
118119 }
119120
@@ -256,7 +257,7 @@ public <I extends FileDirectoryQueryableInformation> List<I> list(String path, C
256257 */
257258 public <I extends FileDirectoryQueryableInformation > List <I > list (String path , Class <I > informationClass , String searchPattern , EnumSet <AccessMask > accessMask ) {
258259 Directory d = openDirectory (path ,
259- accessMask == null ? of (FILE_LIST_DIRECTORY , FILE_READ_ATTRIBUTES , FILE_READ_EA ) : accessMask ,
260+ accessMask == null ? of (FILE_LIST_DIRECTORY , FILE_READ_ATTRIBUTES , FILE_READ_EA ) : accessMask ,
260261 null , ALL , FILE_OPEN , null );
261262 try {
262263 return d .list (informationClass , searchPattern );
@@ -405,37 +406,38 @@ public void rmdir(String path, boolean recursive) throws SMBApiException {
405406 if (path == null || path .isEmpty ()) {
406407 throw new IllegalArgumentException ("rmdir: path should be non-null and non-empty" );
407408 }
408-
409- if (recursive ) {
410- List <FileIdBothDirectoryInformation > list = list (path );
411- for (FileIdBothDirectoryInformation fi : list ) {
412- if (fi .getFileName ().equals ("." ) || fi .getFileName ().equals (".." )) {
413- continue ;
409+ try {
410+ if (recursive ) {
411+ List <FileIdBothDirectoryInformation > list = list (path );
412+ for (FileIdBothDirectoryInformation fi : list ) {
413+ if (fi .getFileName ().equals ("." ) || fi .getFileName ().equals (".." )) {
414+ continue ;
415+ }
416+ String childPath = path + "\\ " + fi .getFileName ();
417+ if (!EnumWithValue .EnumUtils .isSet (fi .getFileAttributes (), FILE_ATTRIBUTE_DIRECTORY )) {
418+ rm (childPath );
419+ } else {
420+ rmdir (childPath , true );
421+ }
414422 }
415- String childPath = path + "\\ " + fi .getFileName ();
416- if (!EnumWithValue .EnumUtils .isSet (fi .getFileAttributes (), FILE_ATTRIBUTE_DIRECTORY )) {
417- rm (childPath );
418- } else {
419- rmdir (childPath , true );
423+ rmdir (path , false );
424+ } else {
425+ try (DiskEntry e = open (
426+ path ,
427+ of (DELETE ),
428+ of (FILE_ATTRIBUTE_DIRECTORY ),
429+ of (FILE_SHARE_DELETE , FILE_SHARE_WRITE , FILE_SHARE_READ ),
430+ FILE_OPEN ,
431+ of (FILE_DIRECTORY_FILE )
432+ )) {
433+ e .deleteOnClose ();
420434 }
421435 }
422- rmdir (path , false );
423- } else {
424- try (DiskEntry e = open (
425- path ,
426- of (DELETE ),
427- of (FILE_ATTRIBUTE_DIRECTORY ),
428- of (FILE_SHARE_DELETE , FILE_SHARE_WRITE , FILE_SHARE_READ ),
429- FILE_OPEN ,
430- of (FILE_DIRECTORY_FILE )
431- )) {
432- e .deleteOnClose ();
433- } catch (SMBApiException sae ) {
434- if (ALREADY_DELETED_STATUS_HANDLER .isSuccess (sae .getStatusCode ())) {
435- return ;
436- }
437- throw sae ;
436+ } catch (SMBApiException sae ) {
437+ if (ALREADY_DELETED_STATUS_HANDLER .isSuccess (sae .getStatusCode ())) {
438+ return ;
438439 }
440+ throw sae ;
439441 }
440442 }
441443
@@ -467,7 +469,8 @@ public void deleteOnClose(SMB2FileId fileId) {
467469 /**
468470 * The SecurityDescriptor(MS-DTYP 2.4.6 SECURITY_DESCRIPTOR) for the Given Path
469471 */
470- public SecurityDescriptor getSecurityInfo (String path , Set <SecurityInformation > securityInfo ) throws SMBApiException {
472+ public SecurityDescriptor getSecurityInfo (String path , Set <SecurityInformation > securityInfo ) throws
473+ SMBApiException {
471474 EnumSet <AccessMask > accessMask = of (READ_CONTROL );
472475 if (securityInfo .contains (SecurityInformation .SACL_SECURITY_INFORMATION )) {
473476 accessMask .add (ACCESS_SYSTEM_SECURITY );
@@ -481,7 +484,8 @@ public SecurityDescriptor getSecurityInfo(String path, Set<SecurityInformation>
481484 /**
482485 * The SecurityDescriptor(MS-DTYP 2.4.6 SECURITY_DESCRIPTOR) for the Given FileId
483486 */
484- public SecurityDescriptor getSecurityInfo (SMB2FileId fileId , Set <SecurityInformation > securityInfo ) throws SMBApiException {
487+ public SecurityDescriptor getSecurityInfo (SMB2FileId fileId , Set <SecurityInformation > securityInfo ) throws
488+ SMBApiException {
485489
486490 byte [] outputBuffer = queryInfo (fileId , SMB2_0_INFO_SECURITY , securityInfo , null , null ).getOutputBuffer ();
487491 try {
@@ -494,12 +498,13 @@ public SecurityDescriptor getSecurityInfo(SMB2FileId fileId, Set<SecurityInforma
494498 /**
495499 * The SecurityDescriptor(MS-DTYP 2.4.6 SECURITY_DESCRIPTOR) for the Given FileId
496500 */
497- public void setSecurityInfo (String path , Set <SecurityInformation > securityInfo , SecurityDescriptor securityDescriptor ) throws SMBApiException {
501+ public void setSecurityInfo (String path , Set <SecurityInformation > securityInfo , SecurityDescriptor
502+ securityDescriptor ) throws SMBApiException {
498503 Set <AccessMask > accessMask = noneOf (AccessMask .class );
499504 if (securityInfo .contains (SecurityInformation .SACL_SECURITY_INFORMATION )) {
500505 accessMask .add (ACCESS_SYSTEM_SECURITY );
501506 }
502- if (securityInfo .contains (SecurityInformation .OWNER_SECURITY_INFORMATION ) || securityInfo .contains (SecurityInformation . GROUP_SECURITY_INFORMATION )) {
507+ if (securityInfo .contains (SecurityInformation .OWNER_SECURITY_INFORMATION ) || securityInfo .contains (SecurityInformation .GROUP_SECURITY_INFORMATION )) {
503508 accessMask .add (WRITE_OWNER );
504509 }
505510 if (securityInfo .contains (SecurityInformation .DACL_SECURITY_INFORMATION )) {
@@ -514,7 +519,8 @@ public void setSecurityInfo(String path, Set<SecurityInformation> securityInfo,
514519 /**
515520 * The SecurityDescriptor(MS-DTYP 2.4.6 SECURITY_DESCRIPTOR) for the Given FileId
516521 */
517- public void setSecurityInfo (SMB2FileId fileId , Set <SecurityInformation > securityInfo , SecurityDescriptor securityDescriptor ) throws SMBApiException {
522+ public void setSecurityInfo (SMB2FileId fileId , Set <SecurityInformation > securityInfo , SecurityDescriptor
523+ securityDescriptor ) throws SMBApiException {
518524 SMBBuffer buffer = new SMBBuffer ();
519525 securityDescriptor .write (buffer );
520526
@@ -534,7 +540,7 @@ public String toString() {
534540
535541 /**
536542 * A return object for the {@link #createFileAndResolve(SmbPath, SMB2ImpersonationLevel, Set, Set, Set, SMB2CreateDisposition, Set)} call.
537- *
543+ * <p>
538544 * This object wraps the {@link SMB2CreateResponse} and the actual {@link Share} which generated it if the path needed to be resolved.
539545 */
540546 static class SMB2CreateResponseContext {
0 commit comments