Skip to content

Commit c478737

Browse files
committed
Add LegacyReadonlyPhysicalStore as default to handle indy legacy storage
1 parent 721bb3d commit c478737

File tree

3 files changed

+65
-1
lines changed

3 files changed

+65
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ log/
1414
# idea
1515
.idea
1616
*.iml
17+
.vscode
1718

1819
# Mobile Tools for Java (J2ME)
1920
.mtj.tmp/

src/main/java/org/commonjava/service/storage/core/FileManagerProducer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public PathMappedFileManager getFileManager()
7272
}
7373
else
7474
{
75-
physicalStore = new FileBasedPhysicalStore( storageConfig.baseDir() );
75+
physicalStore = new LegacyReadonlyPhysicalStore( storageConfig.baseDir() );
7676
}
7777

7878
return new PathMappedFileManager( config, pathDB, physicalStore );
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/**
2+
* Copyright (C) 2021 Red Hat, Inc. (https://github.com/Commonjava/service-parent)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.commonjava.service.storage.core;
17+
18+
import org.commonjava.storage.pathmapped.core.FileBasedPhysicalStore;
19+
import org.commonjava.storage.pathmapped.spi.FileInfo;
20+
import org.slf4j.Logger;
21+
import org.slf4j.LoggerFactory;
22+
23+
import java.io.File;
24+
25+
/**
26+
* Treat legacy package folders (generic-http, maven, npm) as read-only.
27+
* Reads are allowed, while writes target the newer hashed layout.
28+
* Operations that would delete legacy paths are skipped.
29+
*/
30+
public class LegacyReadonlyPhysicalStore extends FileBasedPhysicalStore
31+
{
32+
public static final String PKG_TYPE_MAVEN = "maven";
33+
34+
public static final String PKG_TYPE_NPM = "npm";
35+
36+
public static final String PKG_TYPE_GENERIC_HTTP = "generic-http";
37+
38+
private final Logger logger = LoggerFactory.getLogger( getClass() );
39+
40+
public LegacyReadonlyPhysicalStore( File baseDir )
41+
{
42+
super( baseDir );
43+
}
44+
45+
@Override
46+
public boolean delete( FileInfo fileInfo )
47+
{
48+
String fileStorage = fileInfo.getFileStorage();
49+
if ( isLegacyFile( fileStorage ) )
50+
{
51+
logger.debug( "Skip read-only legacy file: {}", fileStorage );
52+
return true;
53+
}
54+
return super.delete( fileInfo );
55+
}
56+
57+
//Legacy folders: generic-http, maven, npm
58+
private boolean isLegacyFile( String fileStorage )
59+
{
60+
return fileStorage != null && ( fileStorage.startsWith( PKG_TYPE_MAVEN ) || fileStorage.startsWith(
61+
PKG_TYPE_GENERIC_HTTP ) || fileStorage.startsWith( PKG_TYPE_NPM ) );
62+
}
63+
}

0 commit comments

Comments
 (0)