Class ReversibleFileOperations

java.lang.Object
com.atlassian.jira.application.install.ReversibleFileOperations
All Implemented Interfaces:
AutoCloseable

public class ReversibleFileOperations extends Object implements AutoCloseable
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
 
 
Since:
v6.5
  • Constructor Details

    • ReversibleFileOperations

      public ReversibleFileOperations()
  • Method Details

    • removeOnRollback

      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.
    • fileDelete

      public void fileDelete(File file) throws IOException
      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
    • commit

      public void commit() throws IOException
      Commits all pending operations. Not commited operation will be reverted on close.
      Throws:
      IOException
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Throws:
      IOException