Skip to content

Commit 2461b16

Browse files
Navin Surtanibstansberry
authored andcommitted
[AS7-5389] Second commit to 7.1 branch, fixing logging error in FilePersistentObjectStore
1 parent c3087d5 commit 2461b16

File tree

8 files changed

+67
-7
lines changed

8 files changed

+67
-7
lines changed

controller-client/src/main/java/org/jboss/as/controller/client/ControllerClientLogger.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,13 @@ public interface ControllerClientLogger extends BasicLogger {
5555
@Message(id = 10600, value = "Closing leaked controller client")
5656
void leakedControllerClient(@Cause Throwable allocationStackTrace);
5757

58+
/**
59+
* Logs a warning message indicating a temp file could not be deleted.
60+
*
61+
* @param name temp filename
62+
*/
63+
@LogMessage(level = WARN)
64+
@Message(id = 10601, value = "Cannot delete temp file %s, will be deleted on exit")
65+
void cannotDeleteTempFile(String name);
66+
5867
}

controller-client/src/main/java/org/jboss/as/controller/client/impl/InputStreamEntry.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
package org.jboss.as.controller.client.impl;
2424

25+
import org.jboss.as.controller.client.ControllerClientLogger;
2526
import org.jboss.as.protocol.StreamUtils;
2627

2728
import java.io.ByteArrayInputStream;
@@ -116,7 +117,6 @@ public CachingStreamEntry(final InputStream original, final boolean autoClose) {
116117
public synchronized int initialize() throws IOException {
117118
if(temp == null) {
118119
temp = File.createTempFile("client", "stream");
119-
temp.deleteOnExit();
120120
final FileOutputStream os = new FileOutputStream(temp);
121121
try {
122122
StreamUtils.copyStream(original, os);
@@ -144,7 +144,10 @@ public synchronized void copyStream(final DataOutput output) throws IOException
144144

145145
@Override
146146
public synchronized void close() throws IOException {
147-
temp.delete();
147+
if (!temp.delete()) {
148+
ControllerClientLogger.ROOT_LOGGER.cannotDeleteTempFile(temp.getName());
149+
temp.deleteOnExit();
150+
}
148151
temp = null;
149152
}
150153
}

controller/src/main/java/org/jboss/as/controller/ControllerLogger.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,4 +388,13 @@ public interface ControllerLogger extends BasicLogger {
388388
@LogMessage(level = Level.WARN)
389389
@Message(id = 14626, value = "Operation was interrupted before stability could be reached")
390390
void interruptedWaitingStability();
391+
392+
/**
393+
* Logs a warnning message indicating a temp file could not be deleted.
394+
*
395+
* @param name temp filename
396+
*/
397+
@LogMessage(level = Level.WARN)
398+
@Message(id = 14628, value = "Cannot delete temp file %s, will be deleted on exit")
399+
void cannotDeleteTempFile(String name);
391400
}

controller/src/main/java/org/jboss/as/controller/persistence/FilePersistenceResource.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ public class FilePersistenceResource implements ConfigurationPersister.Persisten
5050
FilePersistenceResource(final ModelNode model, final File fileName, final AbstractConfigurationPersister persister) throws ConfigurationPersistenceException {
5151
this.fileName = fileName;
5252
tempFileName = new File(fileName.getParentFile(), fileName.getName() + ".tmp");
53-
tempFileName.deleteOnExit();
5453
this.persister = persister;
5554
marshalled = new ExposedByteArrayOutputStream(1024 * 8);
5655
try {
@@ -111,6 +110,11 @@ protected void moveTempFileToMain() throws ConfigurationPersistenceException {
111110
deleteFile(tempFileName);
112111
} catch (Exception e) {
113112
throw MESSAGES.failedToRenameTempFile(e, tempFileName, fileName);
113+
} finally {
114+
if (tempFileName.exists() && !tempFileName.delete()) {
115+
MGMT_OP_LOGGER.cannotDeleteTempFile(tempFileName.getName());
116+
tempFileName.deleteOnExit();
117+
}
114118
}
115119
}
116120

deployment-repository/src/main/java/org/jboss/as/repository/ContentRepository.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ public byte[] addContent(InputStream stream) throws IOException {
176176
if(hasContent(sha1Bytes)) {
177177
// we've already got this content
178178
if (!tmp.delete()) {
179+
DeploymentRepositoryLogger.ROOT_LOGGER.cannotDeleteTempFile(tmp.getName());
179180
tmp.deleteOnExit();
180181
}
181182
DeploymentRepositoryLogger.ROOT_LOGGER.debugf("Content was already present in repository at location %s", realFile.getAbsolutePath());
@@ -278,9 +279,11 @@ private void moveTempToPermanent(File tmpFile, File permanentFile) throws IOExce
278279

279280
} finally {
280281
if (!tmpFile.delete()) {
282+
DeploymentRepositoryLogger.ROOT_LOGGER.cannotDeleteTempFile(tmpFile.getName());
281283
tmpFile.deleteOnExit();
282284
}
283285
if (localTmp.exists() && !localTmp.delete()) {
286+
DeploymentRepositoryLogger.ROOT_LOGGER.cannotDeleteTempFile(localTmp.getName());
284287
localTmp.deleteOnExit();
285288
}
286289
}
@@ -324,15 +327,18 @@ public void removeContent(byte[] hash, Object reference) {
324327

325328
File file = getDeploymentContentFile(hash, true);
326329
if(!file.delete()) {
330+
DeploymentRepositoryLogger.ROOT_LOGGER.cannotDeleteTempFile(file.getName());
327331
file.deleteOnExit();
328332
}
329333
File parent = file.getParentFile();
330334
if (!parent.delete()) {
335+
DeploymentRepositoryLogger.ROOT_LOGGER.cannotDeleteTempFile(parent.getName());
331336
parent.deleteOnExit();
332337
}
333338
parent = parent.getParentFile();
334339
if (parent.list().length == 0) {
335340
if (!parent.delete()) {
341+
DeploymentRepositoryLogger.ROOT_LOGGER.cannotDeleteTempFile(parent.getName());
336342
parent.deleteOnExit();
337343
}
338344
}

deployment-repository/src/main/java/org/jboss/as/repository/DeploymentRepositoryLogger.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
package org.jboss.as.repository;
2424

2525
import static org.jboss.logging.Logger.Level.INFO;
26+
import static org.jboss.logging.Logger.Level.WARN;
2627

2728
import org.jboss.logging.BasicLogger;
2829
import org.jboss.logging.LogMessage;
@@ -56,4 +57,8 @@ interface DeploymentRepositoryLogger extends BasicLogger {
5657
@LogMessage(level = INFO)
5758
@Message(id = 14901, value = "Content removed from location %s")
5859
void contentRemoved(String path);
60+
61+
@LogMessage(level = WARN)
62+
@Message(id = 14902, value = "Cannot delete temp file %s, will be deleted on exit")
63+
void cannotDeleteTempFile(String path);
5964
}

ejb3/src/main/java/org/jboss/as/ejb3/EjbLogger.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,10 @@ public interface EjbLogger extends BasicLogger {
800800
@Message(id = 14259, value = "BMT stateful bean '%s' did not complete user transaction properly status=%s")
801801
void transactionNotComplete(String componentName, String status);
802802

803+
@LogMessage (level = ERROR)
804+
@Message(id = 14260, value = "Cannot delete cache %s %s, will be deleted on exit")
805+
void cannotDeleteCacheFile(String fileType, String fileName);
806+
803807

804808
// Don't add message ids greater that 14299!!! If you need more first check what EjbMessages is
805809
// using and take more (lower) numbers from the available range for this module. If the range for the module is

ejb3/src/main/java/org/jboss/as/ejb3/cache/spi/impl/FilePersistentObjectStore.java

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import java.security.PrivilegedActionException;
3434
import java.security.PrivilegedExceptionAction;
3535

36+
import org.jboss.as.ejb3.EjbLogger;
3637
import org.jboss.as.ejb3.EjbMessages;
3738
import org.jboss.as.ejb3.cache.Cacheable;
3839
import org.jboss.as.ejb3.cache.PassivationManager;
@@ -70,7 +71,12 @@ private static class DeleteFileAction implements PrivilegedAction<Boolean> {
7071

7172
@Override
7273
public Boolean run() {
73-
return file.delete();
74+
boolean deleted = file.delete();
75+
if (!deleted) {
76+
EjbLogger.EJB3_LOGGER.cannotDeleteCacheFile(file.isDirectory() ? "directory" : "file", file.getName());
77+
file.deleteOnExit();
78+
}
79+
return deleted;
7480
}
7581

7682
static boolean delete(File file) {
@@ -215,7 +221,6 @@ public void start() {
215221
private void establishDirectory(File dir) {
216222
if (!dir.exists()) {
217223
if (MkdirsFileAction.mkdirs(dir)) {
218-
dir.deleteOnExit();
219224
} else if (!dir.exists()) { // this method can be called concurrently, so another thread may have created the dir
220225
throw EjbMessages.MESSAGES.passivationDirectoryCreationFailed(dir.getPath());
221226
}
@@ -228,13 +233,28 @@ private void establishDirectory(File dir) {
228233

229234
@Override
230235
public void stop() {
231-
// TODO: implement
236+
deleteDirectory(baseDirectory);
237+
}
238+
239+
private void deleteDirectory(final File dir) {
240+
if (dir != null && dir.exists()) {
241+
final File[] files = dir.listFiles();
242+
if (files != null) {
243+
for (final File file : files) {
244+
if (file.isDirectory()) {
245+
deleteDirectory(file);
246+
} else {
247+
DeleteFileAction.delete(file);
248+
}
249+
}
250+
}
251+
}
252+
DeleteFileAction.delete(dir);
232253
}
233254

234255
@Override
235256
public void store(V obj) {
236257
File file = getFile(obj.getId());
237-
file.deleteOnExit();
238258
log.tracef("Storing state to %s", file);
239259
try {
240260
FileOutputStream outputStream = null;

0 commit comments

Comments
 (0)