1414package com .google .devtools .build .lib .buildtool ;
1515
1616import com .google .common .base .Joiner ;
17- import com .google .common .base .Preconditions ;
1817import com .google .common .collect .ImmutableList ;
1918import com .google .common .collect .ImmutableSet ;
2019import com .google .common .collect .Iterables ;
3534import com .google .devtools .build .lib .vfs .PathFragment ;
3635import java .io .IOException ;
3736import java .util .ArrayList ;
38- import java .util .Collection ;
3937import java .util .LinkedHashSet ;
4038import java .util .List ;
4139import java .util .Set ;
@@ -186,49 +184,6 @@ public static PathPrettyPrinter getPathPrettyPrinter(
186184 getAllLinkDefinitions (symlinkDefinitions ), symlinkPrefix , productName , workspaceDirectory );
187185 }
188186
189- private static void removeAllSymlinks (
190- List <String > failures , Path workspace , Path outputBase , String symlinkPrefix ) {
191-
192- // Get the prefix directory relative to the workspace.
193- Path symlinkPrefixDirectory = workspace .getRelative (symlinkPrefix );
194- Path directoryWithSymlinks =
195- // Handle the special case when the prefix is just a path.
196- // Otherwise we need to go one level up.
197- symlinkPrefix .endsWith ("/" )
198- ? symlinkPrefixDirectory
199- // This will return the workspace if the prefix was not a directory.
200- : symlinkPrefixDirectory .getParentDirectory ();
201- Preconditions .checkNotNull (
202- directoryWithSymlinks , "Invalid symlink_prefix provided: %s" , symlinkPrefix );
203-
204- // Try to get a list of all symlinks in the workspace.
205- Collection <Path > pathsInWorkspace ;
206- try {
207- pathsInWorkspace = directoryWithSymlinks .getDirectoryEntries ();
208- } catch (IOException e ) {
209- failures .add (
210- String .format (
211- "Failed to list files under path %s: %s" ,
212- directoryWithSymlinks .getPathString (), e .getMessage ()));
213- return ;
214- }
215-
216- // Iterate through all the files and delete any symbolic links that start with the prefix
217- // and point to the output directory.
218- for (Path entry : pathsInWorkspace ) {
219- try {
220- if (entry .isSymbolicLink ()
221- && entry .relativeTo (workspace ).getPathString ().startsWith (symlinkPrefix )
222- && entry .readSymbolicLink ().startsWith (outputBase .asFragment ())) {
223- logger .atFinest ().log ("Removing %s" , entry );
224- entry .delete ();
225- }
226- } catch (IOException e ) {
227- failures .add (String .format ("%s: %s" , entry .getBaseName (), e .getMessage ()));
228- }
229- }
230- }
231-
232187 /**
233188 * Attempts to remove the convenience symlinks in the workspace directory.
234189 *
@@ -242,35 +197,28 @@ private static void removeAllSymlinks(
242197 * @param eventHandler the error eventHandler
243198 * @param symlinkPrefix the symlink prefix which should be removed
244199 * @param productName the product name
245- * @param removeAllConvenienceSymlinks Delete all symlinks with the given prefix, not just
246- * predefined links.
247200 */
248201 public static void removeOutputDirectoryLinks (
249202 Iterable <SymlinkDefinition > symlinkDefinitions ,
250203 Path workspace ,
251204 Path outputBase ,
252205 EventHandler eventHandler ,
253206 String symlinkPrefix ,
254- String productName ,
255- boolean removeAllConvenienceSymlinks ) {
207+ String productName ) {
256208 if (NO_CREATE_SYMLINKS_PREFIX .equals (symlinkPrefix )) {
257209 return ;
258210 }
259211 List <String > failures = new ArrayList <>();
260212
261213 String workspaceBaseName = workspace .getBaseName ();
262214
263- if (removeAllConvenienceSymlinks ) {
264- removeAllSymlinks (failures , workspace , outputBase , symlinkPrefix );
265- } else {
266- for (SymlinkDefinition link : getAllLinkDefinitions (symlinkDefinitions )) {
267- removeLink (
268- workspace ,
269- link .getLinkName (symlinkPrefix , productName , workspaceBaseName ),
270- failures ,
271- ImmutableList .builder (),
272- false );
273- }
215+ for (SymlinkDefinition link : getAllLinkDefinitions (symlinkDefinitions )) {
216+ removeLink (
217+ workspace ,
218+ link .getLinkName (symlinkPrefix , productName , workspaceBaseName ),
219+ failures ,
220+ ImmutableList .builder (),
221+ false );
274222 }
275223
276224 FileSystemUtils .removeDirectoryAndParents (workspace , PathFragment .create (symlinkPrefix ));
0 commit comments