Skip to content

Commit 39782b9

Browse files
committed
Add ignore-readonly for metadta clearing action
1 parent e9441d6 commit 39782b9

2 files changed

Lines changed: 38 additions & 22 deletions

File tree

addons/pkg-maven/common/src/main/java/org/commonjava/indy/pkg/maven/change/MetadataMergePomChangeListener.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package org.commonjava.indy.pkg.maven.change;
1717

18+
import org.commonjava.indy.IndyWorkflowException;
1819
import org.commonjava.indy.content.DownloadManager;
1920
import org.commonjava.indy.core.change.event.IndyFileEventManager;
2021
import org.commonjava.indy.core.content.group.GroupMergeHelper;
@@ -34,6 +35,7 @@
3435
import org.slf4j.Logger;
3536
import org.slf4j.LoggerFactory;
3637

38+
import javax.enterprise.context.ApplicationScoped;
3739
import javax.enterprise.event.Observes;
3840
import javax.inject.Inject;
3941
import java.io.IOException;
@@ -43,7 +45,7 @@
4345
import static org.commonjava.indy.pkg.maven.content.MetadataUtil.getMetadataPath;
4446
import static org.commonjava.indy.util.LocationUtils.getKey;
4547

46-
@javax.enterprise.context.ApplicationScoped
48+
@ApplicationScoped
4749
public class MetadataMergePomChangeListener
4850
{
4951

@@ -155,7 +157,18 @@ private boolean doClear( final ArtifactStore store, final String path )
155157

156158
if ( item.exists() )
157159
{
158-
final boolean result = item.delete();
160+
boolean result = false;
161+
try
162+
{
163+
result = fileManager.delete( store, item.getPath(),
164+
new EventMetadata().set( StoreDataManager.IGNORE_READONLY, true ) );
165+
}
166+
catch ( IndyWorkflowException e )
167+
{
168+
logger.warn( "Deletion failed for metadata clear, transfer is {}, failed reason:{}", item,
169+
e.getMessage() );
170+
}
171+
159172
logger.trace( "Deleted: {} (success? {})", item, result );
160173

161174
if ( item.getPath().endsWith( MavenMetadataMerger.METADATA_NAME ) )

core/src/main/java/org/commonjava/indy/core/content/DefaultDownloadManager.java

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@
8585
import static org.commonjava.indy.change.EventUtils.fireEvent;
8686
import static org.commonjava.indy.core.ctl.PoolUtils.detectOverloadVoid;
8787
import static org.commonjava.indy.data.StoreDataManager.IGNORE_READONLY;
88-
import static org.commonjava.indy.measure.annotation.MetricNamed.DEFAULT;
8988
import static org.commonjava.indy.model.core.StoreType.hosted;
9089
import static org.commonjava.indy.util.ContentUtils.dedupeListing;
9190
import static org.commonjava.maven.galley.model.TransferOperation.DOWNLOAD;
@@ -169,7 +168,7 @@ public List<StoreResource> list( final ArtifactStore store, final String path )
169168
}
170169

171170
@Override
172-
@Measure( timers = @MetricNamed( DEFAULT ) )
171+
@Measure( timers = @MetricNamed() )
173172
public List<StoreResource> list( final ArtifactStore store, final String path, final EventMetadata eventMetadata )
174173
throws IndyWorkflowException
175174
{
@@ -299,7 +298,7 @@ public List<StoreResource> list( final List<? extends ArtifactStore> stores, fin
299298
}
300299

301300
@Override
302-
@Measure( timers = @MetricNamed( DEFAULT ) )
301+
@Measure( timers = @MetricNamed() )
303302
public List<StoreResource> list( final List<? extends ArtifactStore> stores, final String path, final EventMetadata eventMetadata )
304303
throws IndyWorkflowException
305304
{
@@ -355,7 +354,7 @@ public Transfer retrieveFirst( final List<? extends ArtifactStore> stores, final
355354
}
356355

357356
@Override
358-
@Measure( timers = @MetricNamed( DEFAULT ) )
357+
@Measure( timers = @MetricNamed() )
359358
public Transfer retrieveFirst( final List<? extends ArtifactStore> stores, final String path,
360359
final EventMetadata eventMetadata )
361360
throws IndyWorkflowException
@@ -407,7 +406,7 @@ public List<Transfer> retrieveAll( final List<? extends ArtifactStore> stores, f
407406
* @see org.commonjava.indy.core.rest.util.FileManager#downloadAll(java.util.List, java.lang.String)
408407
*/
409408
@Override
410-
@Measure( timers = @MetricNamed( DEFAULT ) )
409+
@Measure( timers = @MetricNamed() )
411410
public List<Transfer> retrieveAll( final List<? extends ArtifactStore> stores, final String path,
412411
final EventMetadata eventMetadata )
413412
throws IndyWorkflowException
@@ -446,7 +445,7 @@ public Transfer retrieve( final ArtifactStore store, final String path )
446445
* java.lang.String)
447446
*/
448447
@Override
449-
@Measure( timers = @MetricNamed( DEFAULT ) )
448+
@Measure( timers = @MetricNamed() )
450449
public Transfer retrieve( final ArtifactStore store, final String path, final EventMetadata eventMetadata )
451450
throws IndyWorkflowException
452451
{
@@ -513,7 +512,7 @@ private Transfer retrieve( final ArtifactStore store, final String path, final b
513512
}
514513

515514
@Override
516-
@Measure( timers = @MetricNamed( DEFAULT ) )
515+
@Measure( timers = @MetricNamed() )
517516
public boolean exists(final ArtifactStore store, String path)
518517
throws IndyWorkflowException
519518
{
@@ -562,7 +561,7 @@ public Transfer store( final ArtifactStore store, final String path, final Input
562561
* java.lang.String, java.io.InputStream)
563562
*/
564563
@Override
565-
@Measure( timers = @MetricNamed( DEFAULT ) )
564+
@Measure( timers = @MetricNamed() )
566565
public Transfer store( final ArtifactStore store, final String path, final InputStream stream,
567566
final TransferOperation op, final EventMetadata eventMetadata )
568567
throws IndyWorkflowException
@@ -593,7 +592,7 @@ public Transfer store( final ArtifactStore store, final String path, final Input
593592

594593
// final ArtifactPathInfo pathInfo = ArtifactPathInfo.parse( path );
595594
final ContentQuality quality = getQuality( path );
596-
if ( quality != null && quality == ContentQuality.SNAPSHOT )
595+
if ( quality == ContentQuality.SNAPSHOT )
597596
{
598597
if ( !deploy.isAllowSnapshots() )
599598
{
@@ -700,7 +699,7 @@ public Transfer store( final List<? extends ArtifactStore> stores, final String
700699
{
701700
if ( !isIgnoreReadonly( eventMetadata ) && storeManager.isReadonly( store ) )
702701
{
703-
logger.debug( "The store {} is readonly, store operation not allowed" );
702+
logger.debug( "The store {} is readonly, store operation not allowed", store.getKey() );
704703
continue;
705704
}
706705
if ( storeIsSuitableFor( store, quality, op ) )
@@ -900,7 +899,7 @@ public Transfer getStorageReference( final ArtifactStore store, final String pat
900899
}
901900

902901
@Override
903-
@Measure( timers = @MetricNamed( DEFAULT ) )
902+
@Measure( timers = @MetricNamed() )
904903
public Transfer getStorageReference( final ArtifactStore store, final String... path )
905904
{
906905
Logger logger = LoggerFactory.getLogger( getClass() );
@@ -911,7 +910,7 @@ public Transfer getStorageReference( final ArtifactStore store, final String...
911910
}
912911

913912
@Override
914-
@Measure( timers = @MetricNamed( DEFAULT ) )
913+
@Measure( timers = @MetricNamed() )
915914
public Transfer getStorageReference( final StoreKey key, final String... path )
916915
throws IndyWorkflowException
917916
{
@@ -943,7 +942,7 @@ public boolean deleteAll( final List<? extends ArtifactStore> stores, final Stri
943942
{
944943
if ( storeManager.isReadonly( store ) )
945944
{
946-
logger.warn( "The store {} is readonly, store operation not allowed" );
945+
logger.warn( "The store {} is readonly, store operation not allowed", store.getKey() );
947946
continue;
948947
}
949948

@@ -974,7 +973,7 @@ public boolean delete( final ArtifactStore store, final String path, final Event
974973
return false;
975974
}
976975

977-
if ( storeManager.isReadonly( store ) )
976+
if ( storeManager.isReadonly( store ) && !isIgnoreReadonly( eventMetadata ) )
978977
{
979978
throw new IndyWorkflowException( ApplicationStatus.METHOD_NOT_ALLOWED.code(),
980979
"The store {} is readonly. If you want to store any content to this store, please modify it to non-readonly",
@@ -983,9 +982,7 @@ public boolean delete( final ArtifactStore store, final String path, final Event
983982

984983
final Transfer item = getStorageReference( store, path == null ? ROOT_PATH : path );
985984

986-
final boolean deleted = doDelete( item, eventMetadata );
987-
988-
return deleted;
985+
return doDelete( item, eventMetadata );
989986
}
990987

991988
/**
@@ -1012,8 +1009,13 @@ private Boolean doDelete( final Transfer item, final EventMetadata eventMetadata
10121009
{
10131010
try
10141011
{
1015-
final ConcreteResource res = item.getResource();
1016-
transfers.delete( res, eventMetadata );
1012+
Location loc = item.getLocation();
1013+
if ( isIgnoreReadonly( eventMetadata ) && loc instanceof CacheOnlyLocation )
1014+
{
1015+
( (CacheOnlyLocation) loc ).setReadonly( false );
1016+
}
1017+
final ConcreteResource resource = new ConcreteResource( loc, item.getPath() );
1018+
transfers.delete( resource, eventMetadata );
10171019
}
10181020
catch ( final TransferException e )
10191021
{
@@ -1139,7 +1141,8 @@ private void doRescan( final Transfer item )
11391141
}
11401142
catch ( final IOException e )
11411143
{
1142-
logger.error( "Failed to list local contents: {}. Reason: {}", e, item, e.getMessage() );
1144+
logger.error(
1145+
String.format( "Failed to list local contents: %s. Reason: %s", item, e.getMessage() ), e );
11431146
}
11441147
}
11451148

0 commit comments

Comments
 (0)