Skip to content

Commit

Permalink
BZ-1063436: avoid double commits by checking if file exists instead o…
Browse files Browse the repository at this point in the history
…f createFile
  • Loading branch information
porcelli committed Feb 10, 2014
1 parent e34779a commit 4110396
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 11 deletions.
Expand Up @@ -51,6 +51,7 @@
import org.uberfire.io.IOService;
import org.uberfire.java.nio.base.options.CommentedOption;
import org.uberfire.java.nio.file.DirectoryStream;
import org.uberfire.java.nio.file.FileAlreadyExistsException;
import org.uberfire.rpc.SessionInfo;
import org.uberfire.security.Identity;
import org.uberfire.workbench.events.ResourceOpenedEvent;
Expand Down Expand Up @@ -109,7 +110,10 @@ public Path create( final Path context,
final org.uberfire.java.nio.file.Path nioPath = Paths.convert( context ).resolve( fileName );
final Path newPath = Paths.convert( nioPath );

ioService.createFile( nioPath );
if ( ioService.exists( nioPath ) ) {
throw new FileAlreadyExistsException( nioPath.toString() );
}

ioService.write( nioPath,
drl,
makeCommentedOption( comment ) );
Expand Down
Expand Up @@ -43,6 +43,7 @@
import org.uberfire.java.nio.base.options.CommentedOption;
import org.uberfire.backend.server.util.Paths;
import org.uberfire.backend.vfs.Path;
import org.uberfire.java.nio.file.FileAlreadyExistsException;
import org.uberfire.rpc.SessionInfo;
import org.uberfire.security.Identity;
import org.uberfire.workbench.events.ResourceOpenedEvent;
Expand Down Expand Up @@ -91,7 +92,10 @@ public Path create( final Path context,
final org.uberfire.java.nio.file.Path nioPath = Paths.convert( context ).resolve( fileName );
final Path newPath = Paths.convert( nioPath );

ioService.createFile( nioPath );
if ( ioService.exists( nioPath ) ) {
throw new FileAlreadyExistsException( nioPath.toString() );
}

ioService.write( nioPath,
content,
makeCommentedOption( comment ) );
Expand Down
Expand Up @@ -43,6 +43,7 @@
import org.kie.workbench.common.services.datamodel.backend.server.builder.util.DataEnumLoader;
import org.uberfire.backend.server.util.Paths;
import org.uberfire.backend.vfs.Path;
import org.uberfire.java.nio.file.FileAlreadyExistsException;
import org.uberfire.rpc.SessionInfo;
import org.uberfire.security.Identity;
import org.uberfire.workbench.events.ResourceOpenedEvent;
Expand Down Expand Up @@ -94,7 +95,10 @@ public Path create( final Path context,
final org.uberfire.java.nio.file.Path nioPath = Paths.convert( context ).resolve( fileName );
final Path newPath = Paths.convert( nioPath );

ioService.createFile( nioPath );
if ( ioService.exists( nioPath ) ) {
throw new FileAlreadyExistsException( nioPath.toString() );
}

ioService.write( nioPath,
content,
makeCommentedOption( comment ) );
Expand Down
Expand Up @@ -50,6 +50,7 @@
import org.kie.workbench.common.services.datamodel.backend.server.service.DataModelService;
import org.uberfire.backend.server.util.Paths;
import org.uberfire.backend.vfs.Path;
import org.uberfire.java.nio.file.FileAlreadyExistsException;
import org.uberfire.rpc.SessionInfo;
import org.uberfire.security.Identity;
import org.uberfire.workbench.events.ResourceOpenedEvent;
Expand Down Expand Up @@ -113,7 +114,10 @@ public Path create( final Path context,
final org.uberfire.java.nio.file.Path nioPath = Paths.convert( context ).resolve( fileName );
final Path newPath = Paths.convert( nioPath );

ioService.createFile( nioPath );
if ( ioService.exists( nioPath ) ) {
throw new FileAlreadyExistsException( nioPath.toString() );
}

ioService.write( nioPath,
GlobalsPersistence.getInstance().marshal( content ),
makeCommentedOption( comment ) );
Expand Down
Expand Up @@ -36,7 +36,6 @@
import org.guvnor.common.services.backend.exceptions.ExceptionUtilities;
import org.guvnor.common.services.backend.file.JavaFileFilter;
import org.guvnor.common.services.backend.validation.GenericValidator;
import org.guvnor.common.services.project.builder.events.InvalidateDMOProjectCacheEvent;
import org.guvnor.common.services.project.model.Package;
import org.guvnor.common.services.project.service.ProjectService;
import org.guvnor.common.services.shared.file.CopyService;
Expand All @@ -56,6 +55,7 @@
import org.uberfire.backend.vfs.Path;
import org.uberfire.io.IOService;
import org.uberfire.java.nio.base.options.CommentedOption;
import org.uberfire.java.nio.file.FileAlreadyExistsException;
import org.uberfire.rpc.SessionInfo;
import org.uberfire.security.Identity;
import org.uberfire.workbench.events.ResourceOpenedEvent;
Expand Down Expand Up @@ -123,7 +123,10 @@ public Path create( final Path context,
final org.uberfire.java.nio.file.Path nioPath = Paths.convert( context ).resolve( fileName );
final Path newPath = Paths.convert( nioPath );

ioService.createFile( nioPath );
if ( ioService.exists( nioPath ) ) {
throw new FileAlreadyExistsException( nioPath.toString() );
}

ioService.write( nioPath,
GuidedDTXMLPersistence.getInstance().marshal( content ),
makeCommentedOption( comment ) );
Expand Down
Expand Up @@ -51,6 +51,7 @@
import org.uberfire.backend.server.util.Paths;
import org.uberfire.backend.vfs.Path;
import org.uberfire.io.IOService;
import org.uberfire.java.nio.file.FileAlreadyExistsException;
import org.uberfire.rpc.SessionInfo;
import org.uberfire.workbench.events.ResourceOpenedEvent;

Expand Down Expand Up @@ -119,7 +120,10 @@ public Path create( final Path context,
final org.uberfire.java.nio.file.Path nioPath = Paths.convert( context ).resolve( fileName );
final Path newPath = Paths.convert( nioPath );

ioService.createFile( nioPath );
if ( ioService.exists( nioPath ) ) {
throw new FileAlreadyExistsException( nioPath.toString() );
}

ioService.write( nioPath,
toSource( newPath,
model ),
Expand Down
Expand Up @@ -50,6 +50,7 @@
import org.uberfire.backend.vfs.Path;
import org.uberfire.io.IOService;
import org.uberfire.java.nio.base.options.CommentedOption;
import org.uberfire.java.nio.file.FileAlreadyExistsException;
import org.uberfire.rpc.SessionInfo;
import org.uberfire.security.Identity;
import org.uberfire.workbench.events.ResourceOpenedEvent;
Expand Down Expand Up @@ -105,7 +106,10 @@ public Path create( final Path context,
final org.uberfire.java.nio.file.Path nioPath = Paths.convert( context ).resolve( fileName );
final Path newPath = Paths.convert( nioPath );

ioService.createFile( nioPath );
if ( ioService.exists( nioPath ) ) {
throw new FileAlreadyExistsException( nioPath.toString() );
}

ioService.write( nioPath,
GuidedScoreCardXMLPersistence.getInstance().marshal( content ),
makeCommentedOption( comment ) );
Expand Down
Expand Up @@ -53,6 +53,7 @@
import org.uberfire.backend.server.util.Paths;
import org.uberfire.backend.vfs.Path;
import org.uberfire.io.IOService;
import org.uberfire.java.nio.file.FileAlreadyExistsException;
import org.uberfire.rpc.SessionInfo;
import org.uberfire.workbench.events.ResourceOpenedEvent;

Expand Down Expand Up @@ -118,7 +119,10 @@ public Path create( final Path context,
final org.uberfire.java.nio.file.Path nioPath = Paths.convert( context ).resolve( fileName );
final Path newPath = Paths.convert( nioPath );

ioService.createFile( nioPath );
if ( ioService.exists( nioPath ) ) {
throw new FileAlreadyExistsException( nioPath.toString() );
}

ioService.write( nioPath,
RuleTemplateModelXMLPersistenceImpl.getInstance().marshal( content ),
utilities.makeCommentedOption( comment ) );
Expand Down
Expand Up @@ -57,6 +57,7 @@
import org.uberfire.io.IOService;
import org.uberfire.java.nio.base.options.CommentedOption;
import org.uberfire.java.nio.file.DirectoryStream;
import org.uberfire.java.nio.file.FileAlreadyExistsException;
import org.uberfire.java.nio.file.Files;
import org.uberfire.rpc.SessionInfo;
import org.uberfire.security.Identity;
Expand Down Expand Up @@ -116,7 +117,10 @@ public Path create( final Path context,
final org.uberfire.java.nio.file.Path nioPath = Paths.convert( context ).resolve( fileName );
final Path newPath = Paths.convert( nioPath );

ioService.createFile( nioPath );
if ( ioService.exists( nioPath ) ) {
throw new FileAlreadyExistsException( nioPath.toString() );
}

ioService.write( nioPath,
ScenarioXMLPersistence.getInstance().marshal( content ),
makeCommentedOption( comment ) );
Expand Down
Expand Up @@ -71,6 +71,7 @@
import org.uberfire.backend.vfs.Path;
import org.uberfire.io.IOService;
import org.uberfire.java.nio.base.options.CommentedOption;
import org.uberfire.java.nio.file.FileAlreadyExistsException;
import org.uberfire.rpc.SessionInfo;
import org.uberfire.security.Identity;
import org.uberfire.workbench.events.ResourceOpenedEvent;
Expand Down Expand Up @@ -166,7 +167,10 @@ public Path create( final Path context,
final org.uberfire.java.nio.file.Path nioPath = Paths.convert( context ).resolve( fileName );
final Path newPath = Paths.convert( nioPath );

ioService.createFile( nioPath );
if ( ioService.exists( nioPath ) ) {
throw new FileAlreadyExistsException( nioPath.toString() );
}

ioService.write( nioPath,
defaultDefinition,
makeCommentedOption( comment ) );
Expand Down

0 comments on commit 4110396

Please sign in to comment.