[MRM-1769]Can't uploads multiple artifacts of different types

fix issue deleting temporary files

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1546471 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2013-11-28 23:13:21 +00:00
parent 91cc505d00
commit 4f7f1d74f9
3 changed files with 29 additions and 12 deletions

View File

@ -85,7 +85,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
/** /**
* @author Olivier Lamy * @author Olivier Lamy
*/ */
@Service( "fileUploadService#rest" ) @Service("fileUploadService#rest")
public class DefaultFileUploadService public class DefaultFileUploadService
extends AbstractRestService extends AbstractRestService
implements FileUploadService implements FileUploadService
@ -107,7 +107,7 @@ public class DefaultFileUploadService
private ChecksumAlgorithm[] algorithms = new ChecksumAlgorithm[]{ ChecksumAlgorithm.SHA1, ChecksumAlgorithm.MD5 }; private ChecksumAlgorithm[] algorithms = new ChecksumAlgorithm[]{ ChecksumAlgorithm.SHA1, ChecksumAlgorithm.MD5 };
@Inject @Inject
@Named( value = "archivaTaskScheduler#repository" ) @Named(value = "archivaTaskScheduler#repository")
private ArchivaTaskScheduler scheduler; private ArchivaTaskScheduler scheduler;
private String getStringValue( MultipartBody multipartBody, String attachmentId ) private String getStringValue( MultipartBody multipartBody, String attachmentId )
@ -125,6 +125,7 @@ public class DefaultFileUploadService
{ {
String classifier = getStringValue( multipartBody, "classifier" ); String classifier = getStringValue( multipartBody, "classifier" );
String packaging = getStringValue( multipartBody, "packaging" );
// skygo: http header form pomFile was once sending 1 for true and void for false // skygo: http header form pomFile was once sending 1 for true and void for false
// leading to permanent false value for pomFile if using toBoolean(); use , "1", "" // leading to permanent false value for pomFile if using toBoolean(); use , "1", ""
boolean pomFile = BooleanUtils.toBoolean( getStringValue( multipartBody, "pomFile" ) ); boolean pomFile = BooleanUtils.toBoolean( getStringValue( multipartBody, "pomFile" ) );
@ -142,6 +143,7 @@ public class DefaultFileUploadService
fileMetadata.setClassifier( classifier ); fileMetadata.setClassifier( classifier );
fileMetadata.setDeleteUrl( tmpFile.getName() ); fileMetadata.setDeleteUrl( tmpFile.getName() );
fileMetadata.setPomFile( pomFile ); fileMetadata.setPomFile( pomFile );
fileMetadata.setPackaging( packaging );
log.info( "uploading file: {}", fileMetadata ); log.info( "uploading file: {}", fileMetadata );
@ -181,8 +183,7 @@ public class DefaultFileUploadService
{ {
File file = new File( SystemUtils.getJavaIoTmpDir(), fileName ); File file = new File( SystemUtils.getJavaIoTmpDir(), fileName );
log.debug( "delete file:{},exists:{}", file.getPath(), file.exists() ); log.debug( "delete file:{},exists:{}", file.getPath(), file.exists() );
boolean removed = getSessionFileMetadatas().remove( boolean removed = getSessionFileMetadatas().remove( new FileMetadata( fileName ) );
new FileMetadata( SystemUtils.getJavaIoTmpDir().getPath() + "/" + fileName ) );
if ( file.exists() ) if ( file.exists() )
{ {
return file.delete(); return file.delete();
@ -196,8 +197,9 @@ public class DefaultFileUploadService
List<FileMetadata> fileMetadatas = new ArrayList( getSessionFileMetadatas() ); List<FileMetadata> fileMetadatas = new ArrayList( getSessionFileMetadatas() );
for ( FileMetadata fileMetadata : fileMetadatas ) for ( FileMetadata fileMetadata : fileMetadatas )
{ {
deleteFile( new File( fileMetadata.getServerFileName() ).getName() ); deleteFile( new File( fileMetadata.getServerFileName() ).getPath() );
} }
getSessionFileMetadatas().clear();
return Boolean.TRUE; return Boolean.TRUE;
} }
@ -210,8 +212,8 @@ public class DefaultFileUploadService
return fileMetadatas == null ? Collections.<FileMetadata>emptyList() : fileMetadatas; return fileMetadatas == null ? Collections.<FileMetadata>emptyList() : fileMetadatas;
} }
public Boolean save( String repositoryId, String groupId, String artifactId, String version, public Boolean save( String repositoryId, String groupId, String artifactId, String version, String packaging,
String packaging, boolean generatePom ) boolean generatePom )
throws ArchivaRestServiceException throws ArchivaRestServiceException
{ {
repositoryId = StringUtils.trim( repositoryId ); repositoryId = StringUtils.trim( repositoryId );
@ -362,7 +364,8 @@ public class DefaultFileUploadService
artifactReference.setGroupId( groupId ); artifactReference.setGroupId( groupId );
artifactReference.setVersion( version ); artifactReference.setVersion( version );
artifactReference.setClassifier( fileMetadata.getClassifier() ); artifactReference.setClassifier( fileMetadata.getClassifier() );
artifactReference.setType( packaging ); artifactReference.setType(
StringUtils.isEmpty( fileMetadata.getPackaging() ) ? packaging : fileMetadata.getPackaging() );
ManagedRepositoryContent repository = repositoryFactory.getManagedRepositoryContent( repositoryId ); ManagedRepositoryContent repository = repositoryFactory.getManagedRepositoryContent( repositoryId );
@ -430,6 +433,7 @@ public class DefaultFileUploadService
} }
catch ( IOException ie ) catch ( IOException ie )
{ {
log.error( "IOException copying file: {}", ie.getMessage(), ie );
throw new ArchivaRestServiceException( throw new ArchivaRestServiceException(
"Overwriting released artifacts in repository '" + repoConfig.getId() + "' is not allowed.", "Overwriting released artifacts in repository '" + repoConfig.getId() + "' is not allowed.",
Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), ie ); Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), ie );

View File

@ -45,6 +45,8 @@ public class FileMetadata
private String classifier; private String classifier;
private String packaging;
private boolean pomFile; private boolean pomFile;
public FileMetadata() public FileMetadata()
@ -157,6 +159,16 @@ public class FileMetadata
this.serverFileName = serverFileName; this.serverFileName = serverFileName;
} }
public String getPackaging()
{
return packaging;
}
public void setPackaging( String packaging )
{
this.packaging = packaging;
}
@Override @Override
public boolean equals( Object o ) public boolean equals( Object o )
{ {
@ -188,9 +200,8 @@ public class FileMetadata
@Override @Override
public String toString() public String toString()
{ {
final StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder( "FileMetadata{" );
sb.append( "FileMetadata" ); sb.append( "name='" ).append( name ).append( '\'' );
sb.append( "{name='" ).append( name ).append( '\'' );
sb.append( ", serverFileName='" ).append( serverFileName ).append( '\'' ); sb.append( ", serverFileName='" ).append( serverFileName ).append( '\'' );
sb.append( ", size=" ).append( size ); sb.append( ", size=" ).append( size );
sb.append( ", url='" ).append( url ).append( '\'' ); sb.append( ", url='" ).append( url ).append( '\'' );
@ -198,6 +209,7 @@ public class FileMetadata
sb.append( ", deleteType='" ).append( deleteType ).append( '\'' ); sb.append( ", deleteType='" ).append( deleteType ).append( '\'' );
sb.append( ", errorKey='" ).append( errorKey ).append( '\'' ); sb.append( ", errorKey='" ).append( errorKey ).append( '\'' );
sb.append( ", classifier='" ).append( classifier ).append( '\'' ); sb.append( ", classifier='" ).append( classifier ).append( '\'' );
sb.append( ", packaging='" ).append( packaging ).append( '\'' );
sb.append( ", pomFile=" ).append( pomFile ); sb.append( ", pomFile=" ).append( pomFile );
sb.append( '}' ); sb.append( '}' );
return sb.toString(); return sb.toString();

View File

@ -734,7 +734,8 @@
{% for (var i=0, file; file=o.files[i]; i++) { %} {% for (var i=0, file; file=o.files[i]; i++) { %}
<tr class="template-upload"> <tr class="template-upload">
<td class="name"><span>{%=file.name%}</span></td> <td class="name"><span>{%=file.name%}</span></td>
<td><input type="text" id="classifier" name="classifier" placeholder="classifier" value=""/></td> <td><input type="text" class="input-small" id="classifier" name="classifier" placeholder="classifier" value=""/></td>
<td><input type="text" class="input-small" id="packaging" name="packaging" placeholder="packaging" value=""></td>
<td><span>pomFile:</span><input type="checkbox" id="pomFile" name="pomFile"/></td> <td><span>pomFile:</span><input type="checkbox" id="pomFile" name="pomFile"/></td>
<td class="size"><span>{%=o.formatFileSize(file.size)%}</span></td> <td class="size"><span>{%=o.formatFileSize(file.size)%}</span></td>
{% if (file.error) { %} {% if (file.error) { %}