mirror of https://github.com/apache/archiva.git
fix concurrent access when uploading files in parallel
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1308258 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
67bf9acaff
commit
c3ee919adc
|
@ -398,5 +398,7 @@ fileupload.packaging=Packaging
|
||||||
fileupload.generatePom=Generate Maven POM
|
fileupload.generatePom=Generate Maven POM
|
||||||
fileupload.repositoryId=Repository Id
|
fileupload.repositoryId=Repository Id
|
||||||
fileupload.save=Save Files
|
fileupload.save=Save Files
|
||||||
|
fileupload.upload.required=You must upload your files first.
|
||||||
|
fileupload.artifacts.saved=Artifacts uploaded and saved on Server side.
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -81,6 +81,7 @@ import java.util.Date;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Olivier Lamy
|
* @author Olivier Lamy
|
||||||
|
@ -123,13 +124,6 @@ public class DefaultFileUploadService
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
String groupId = getStringValue( multipartBody, "groupId" );
|
|
||||||
|
|
||||||
String artifactId = getStringValue( multipartBody, "artifactId" );
|
|
||||||
|
|
||||||
String version = getStringValue( multipartBody, "version" );
|
|
||||||
|
|
||||||
String packaging = getStringValue( multipartBody, "packaging" );
|
|
||||||
|
|
||||||
String classifier = getStringValue( multipartBody, "classifier" );
|
String classifier = getStringValue( multipartBody, "classifier" );
|
||||||
boolean pomFile = BooleanUtils.toBoolean( getStringValue( multipartBody, "pomFile" ) );
|
boolean pomFile = BooleanUtils.toBoolean( getStringValue( multipartBody, "pomFile" ) );
|
||||||
|
@ -148,17 +142,12 @@ public class DefaultFileUploadService
|
||||||
fileMetadata.setDeleteUrl( tmpFile.getName() );
|
fileMetadata.setDeleteUrl( tmpFile.getName() );
|
||||||
fileMetadata.setPomFile( pomFile );
|
fileMetadata.setPomFile( pomFile );
|
||||||
|
|
||||||
log.info( "uploading file:{}", fileMetadata );
|
log.info( "uploading file: {}", fileMetadata );
|
||||||
|
|
||||||
List<FileMetadata> fileMetadatas =
|
List<FileMetadata> fileMetadatas = getSessionFilesList();
|
||||||
(List<FileMetadata>) httpServletRequest.getSession().getAttribute( FILES_SESSION_KEY );
|
|
||||||
|
|
||||||
if ( fileMetadatas == null )
|
|
||||||
{
|
|
||||||
fileMetadatas = new ArrayList<FileMetadata>( 1 );
|
|
||||||
}
|
|
||||||
fileMetadatas.add( fileMetadata );
|
fileMetadatas.add( fileMetadata );
|
||||||
httpServletRequest.getSession().setAttribute( FILES_SESSION_KEY, fileMetadatas );
|
|
||||||
return fileMetadata;
|
return fileMetadata;
|
||||||
}
|
}
|
||||||
catch ( IOException e )
|
catch ( IOException e )
|
||||||
|
@ -169,6 +158,23 @@ public class DefaultFileUploadService
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* FIXME must be per session synchronized not globally
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
protected synchronized List<FileMetadata> getSessionFilesList()
|
||||||
|
{
|
||||||
|
List<FileMetadata> fileMetadatas =
|
||||||
|
(List<FileMetadata>) httpServletRequest.getSession().getAttribute( FILES_SESSION_KEY );
|
||||||
|
if ( fileMetadatas == null )
|
||||||
|
{
|
||||||
|
fileMetadatas = new CopyOnWriteArrayList<FileMetadata>();
|
||||||
|
httpServletRequest.getSession().setAttribute( FILES_SESSION_KEY, fileMetadatas );
|
||||||
|
}
|
||||||
|
return fileMetadatas;
|
||||||
|
}
|
||||||
|
|
||||||
public Boolean deleteFile( String fileName )
|
public Boolean deleteFile( String fileName )
|
||||||
throws ArchivaRestServiceException
|
throws ArchivaRestServiceException
|
||||||
{
|
{
|
||||||
|
@ -206,8 +212,7 @@ public class DefaultFileUploadService
|
||||||
String packaging, final boolean generatePom )
|
String packaging, final boolean generatePom )
|
||||||
throws ArchivaRestServiceException
|
throws ArchivaRestServiceException
|
||||||
{
|
{
|
||||||
List<FileMetadata> fileMetadatas =
|
List<FileMetadata> fileMetadatas = getSessionFilesList();
|
||||||
(List<FileMetadata>) httpServletRequest.getSession().getAttribute( FILES_SESSION_KEY );
|
|
||||||
if ( fileMetadatas == null || fileMetadatas.isEmpty() )
|
if ( fileMetadatas == null || fileMetadatas.isEmpty() )
|
||||||
{
|
{
|
||||||
return Boolean.FALSE;
|
return Boolean.FALSE;
|
||||||
|
@ -230,6 +235,7 @@ public class DefaultFileUploadService
|
||||||
saveFile( repositoryId, fileMetadata, generatePom && !pomGenerated, groupId, artifactId, version,
|
saveFile( repositoryId, fileMetadata, generatePom && !pomGenerated, groupId, artifactId, version,
|
||||||
packaging );
|
packaging );
|
||||||
pomGenerated = true;
|
pomGenerated = true;
|
||||||
|
deleteFile( fileMetadata.getServerFileName() );
|
||||||
}
|
}
|
||||||
|
|
||||||
filesToAdd = Iterables.filter( fileMetadatas, new Predicate<FileMetadata>()
|
filesToAdd = Iterables.filter( fileMetadatas, new Predicate<FileMetadata>()
|
||||||
|
@ -246,6 +252,7 @@ public class DefaultFileUploadService
|
||||||
FileMetadata fileMetadata = iterator.next();
|
FileMetadata fileMetadata = iterator.next();
|
||||||
log.debug( "fileToAdd: {}", fileMetadata );
|
log.debug( "fileToAdd: {}", fileMetadata );
|
||||||
savePomFile( repositoryId, fileMetadata, groupId, artifactId, version, packaging );
|
savePomFile( repositoryId, fileMetadata, groupId, artifactId, version, packaging );
|
||||||
|
deleteFile( fileMetadata.getServerFileName() );
|
||||||
}
|
}
|
||||||
|
|
||||||
return Boolean.TRUE;
|
return Boolean.TRUE;
|
||||||
|
|
|
@ -55,7 +55,7 @@ define("archiva.artifacts-management",["jquery","i18n","order!utils","order!jque
|
||||||
type: "GET",
|
type: "GET",
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
|
displaySuccessMessage($.i18n.prop("fileupload.artifacts.saved"));
|
||||||
},
|
},
|
||||||
error: function(data) {
|
error: function(data) {
|
||||||
var res = $.parseJSON(data.responseText);
|
var res = $.parseJSON(data.responseText);
|
||||||
|
|
Loading…
Reference in New Issue