@@ -89,8 +89,8 @@ public void run(ActionContext context) throws Exception {
8989
9090 configuration .setBoolean ("fs.gs.impl.disable.cache" , true );
9191
92- List <Path > gcsPaths = new ArrayList <>();
93- List <GCSPath > gcsPathsWild = new ArrayList <>();
92+ List <String > gcsPaths = new ArrayList <>();
93+ List <String > gcsPathsWild = new ArrayList <>();
9494 Storage storage = GCPUtils .getStorage (config .getProject (), credentials );
9595 for (String path : config .getPaths ()) {
9696 GCSPath gcsPath = GCSPath .from (path );
@@ -103,20 +103,22 @@ public void run(ActionContext context) throws Exception {
103103 String .format ("Unable to access or create bucket %s. " , gcsPath .getBucket ())
104104 + "Ensure you entered the correct bucket path and have permissions for it." , e );
105105 }
106- if (gcsPath .getUri ().toString ().contains ("*" )) {
107- gcsPathsWild .add (gcsPath );
106+ String exactGCSPath = "gs://" + gcsPath .getBucket () + "/" + gcsPath .getName ();
107+ if (exactGCSPath .contains ("*" )) {
108+ gcsPathsWild .add (exactGCSPath );
108109 } else {
109- gcsPaths .add (new Path ( gcsPath . getUri ()) );
110+ gcsPaths .add (exactGCSPath );
110111 }
111112 }
112113
113114 FileSystem fs ;
114115 int deleteCount = 0 ;
115- for (Path gcsPath : gcsPaths ) {
116+ for (String gcsPathStr : gcsPaths ) {
117+ Path gcsPath = new Path (gcsPathStr );
116118 try {
117119 fs = gcsPath .getFileSystem (configuration );
118120 } catch (IOException e ) {
119- LOG .info ("Failed deleting file " + gcsPath . toUri (). getPath () + ", " + e .getMessage ());
121+ LOG .info ("Failed deleting file " + gcsPathStr + ", " + e .getMessage ());
120122 // no-op.
121123 continue ;
122124 }
@@ -126,22 +128,25 @@ public void run(ActionContext context) throws Exception {
126128 deleteCount ++;
127129 } catch (IOException e ) {
128130 LOG .warn (
129- String .format ("Failed to delete path '%s'" , gcsPath )
131+ String .format ("Failed to delete path '%s'" , gcsPathStr )
130132 );
131133 }
132134 }
133135 }
134136
135- for (GCSPath gcsPath : gcsPathsWild ) {
136- String regex = ("\\ Q" + gcsPath .getUri ().toString () + "\\ E" ).replace ("*" , "\\ E[^/]*\\ Q" ) + "(/.*)?" ;
137+ for (String gcsPathStr : gcsPathsWild ) {
138+ // Match text literally for any characters except one wildcard character "*".
139+ // "*" will be used to represent any characters.
140+ String regex = ("\\ Q" + gcsPathStr + "\\ E" ).replace ("*" , "\\ E[^/]*\\ Q" ) + "(/.*)?" ;
141+ Path gcsPath = new Path (gcsPathStr );
137142 try {
138- fs = new Path ( gcsPath . getUri ()) .getFileSystem (configuration );
143+ fs = gcsPath .getFileSystem (configuration );
139144 } catch (IOException e ) {
140- LOG .info ("Failed deleting file " + gcsPath . getUri (). getPath () + ", " + e .getMessage ());
145+ LOG .info ("Failed deleting file " + gcsPathStr + ", " + e .getMessage ());
141146 // no-op.
142147 continue ;
143148 }
144- Page <Blob > blobs = storage .list (gcsPath .getBucket ());
149+ Page <Blob > blobs = storage .list (GCSPath . from ( gcsPathStr ) .getBucket ());
145150 for (Blob blob : blobs .iterateAll ()) {
146151 Path filePath = new Path ("gs://" + blob .getBucket () + "/" + blob .getName ());
147152 if ((filePath .toString () + "/" ).matches (regex )) {
@@ -153,7 +158,7 @@ public void run(ActionContext context) throws Exception {
153158 deleteCount ++;
154159 } catch (IOException e ) {
155160 LOG .warn (
156- String .format ("Failed to delete path '%s'" , gcsPath )
161+ String .format ("Failed to delete path '%s'" , gcsPathStr )
157162 );
158163 }
159164 } else {
0 commit comments