Skip to content

Commit

Permalink
fix: Try to create the temporary directory if it does not exits
Browse files Browse the repository at this point in the history
Try to create the temporary directory if it does not exits when running.
  • Loading branch information
yuyang733 committed Sep 1, 2022
1 parent 18d71df commit 445ddc4
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,14 @@ public CosNByteBuffer create(int size) {
}

if (!this.tmpDir.exists()) {
LOG.error("The tmp dir does not exist.");
LOG.warn("The tmp dir does not exist.");
// try to create the tmp directory.
try {
CosNMappedBufferFactory.createDir(this.tmpDir.getAbsolutePath());
} catch (IOException e) {
LOG.error("Try to create the tmp dir [{}] failed.", this.tmpDir.getAbsolutePath(), e);
return null;
}
}

try {
Expand All @@ -79,7 +86,7 @@ public CosNByteBuffer create(int size) {
randomAccessFile.setLength(size);
MappedByteBuffer buf =
randomAccessFile.getChannel().map(FileChannel.MapMode.READ_WRITE, 0, size);
return new CosNMappedBuffer(buf, randomAccessFile, tmpFile);
return (null != buf) ? new CosNMappedBuffer(buf, randomAccessFile, tmpFile) : null;
} catch (IOException e) {
LOG.error("Create tmp file failed. Tmp dir: {}", this.tmpDir, e);
return null;
Expand Down

0 comments on commit 445ddc4

Please sign in to comment.