-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Upload with ".tmp" suffix and rename file name after upload #37
Conversation
d523562
to
715a8f8
Compare
715a8f8
to
ba43aba
Compare
@tvhung83 Could you review this? |
Sure, taking a look. |
@Override | ||
public Void call() throws IOException | ||
{ | ||
FileObject remoteFile = newSftpFile(getSftpFileUri(remotePath)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor (optional): we can have multiple resources in one try (...)
:
try (FileObject remoteFile = newSftpFile(getSftpFileUri(remotePath));
BufferedOutputStream outputStream = new BufferedOutputStream(remoteFile.getContent().getOutputStream());
BufferedInputStream inputStream = new BufferedInputStream(new FileInputStream(localTempFile))
) {
logger.info("new sftp file: {}", remoteFile.getPublicURIString());
IOUtils.copy(inputStream, outputStream);
}
It can help to ensure all resources are closed properly :)
private FileObject newSftpFile(final URI sftpUri) throws FileSystemException | ||
{ | ||
FileObject file = manager.resolveFile(sftpUri.toString(), fsOptions); | ||
if (file.exists()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: maybe it's nice to have a warn log, that file is going to be overwritten.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Fixed at 5e6e74f
file.delete(); | ||
} | ||
if (file.getParent().exists()) { | ||
logger.info("parent directory {} exists there", file.getParent().getPublicURIString()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto: perhaps a warn log is better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think info log is fine because existing parent directory isn't unexpected status.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it, this method is about file, not directory creation, so I'm okay with info log here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, just some minor comments (changes are optional)
sftpUtils.uploadFile(tempFile, temporaryFileName); | ||
|
||
Map<String, String> executedFiles = new HashMap<>(); | ||
executedFiles.put("temporary_filename", fileName + temporaryFileSuffix); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: can use temporaryFileName
:)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed at e2b2720
Current implementation has a problem that part of remote files remains at remote when one of tasks failed.
Some users are checking remote file("/path/to/file.txt") existence with job scheduler or something tools for post processing.
I changed implementation to set
temporary_filename
andreal_filename
to Embulk TaskReport atSftpFileOutput.commit()
.After all tasks completed, plugin will get each file name sets and rename remote files.
Of course, temporary file will be left in remote server "/path/to/file.txt.tmp".
However, this is help full for simple mechanical check.
I tried to add more test cases #39. However, this doesn't work due to permission problem of uploaded files. I think something "hack" is needed.