|
| 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