Class ReversibleFileOperations
java.lang.Object
com.atlassian.jira.application.install.ReversibleFileOperations
- All Implemented Interfaces:
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
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.
-
Constructor Details
-
ReversibleFileOperations
public ReversibleFileOperations()
-
-
Method Details
-
removeOnRollback
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
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
Commits all pending operations. Not commited operation will be reverted on close.- Throws:
IOException
-
close
- Specified by:
close
in interfaceAutoCloseable
- Throws:
IOException
-