public class

ReversibleFileOperations

extends Object
implements AutoCloseable
java.lang.Object
   ↳ com.atlassian.jira.application.install.ReversibleFileOperations

Class Overview

This class is intended to be used with try-with-resources. You have to explicitly commit operation by calling commit(). All uncomitted operations will be reverted when try block is finalized. ie.:

try (ReversibleFileOperations reversibleFileOperations = new ReversibleFileOperations())
 {
    reversibleFileOperations.fileDelete(file1);
    reversibleFileOperations.fileDelete(file2);
    reversibleFileOperaions.commit()
  // exception will revert all not commited operations
 }
 

Summary

Public Constructors
ReversibleFileOperations()
Public Methods
void close()
void commit()
Commits all pending operations.
void fileDelete(File file)
Call this to perform deletion operation on file.
void removeOnRollback(File file)
Call this right after you created a file.
[Expand]
Inherited Methods
From class java.lang.Object
From interface java.lang.AutoCloseable

Public Constructors

public ReversibleFileOperations ()

Public Methods

public void close ()

Throws
IOException

public void commit ()

Commits all pending operations. Not commited operation will be reverted on close.

Throws
IOException

public void fileDelete (File file)

Call this to perform deletion operation on file. It will rename given file to some backup file. On commit it will delete backup file and on revert it rename backup file back to its original name. If given file doesn't exist operation is ignored.

Throws
IOException

public void removeOnRollback (File file)

Call this right after you created a file. By itself it doesn't perform any operations on filesystem on call and on commit. It will delete created file on revert.