Skip to content
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

fix:only create tmp directory when compression is on #806

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 27 additions & 22 deletions lib/file_transfer_agent/file_transfer_agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,11 +353,13 @@
*/
async function uploadOneFile(meta) {
meta['realSrcFilePath'] = meta['srcFilePath'];
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'tmp'));
meta['tmpDir'] = tmpDir;

try {
if (meta['requireCompress']) {
const result = await SnowflakeFileUtil.compressFileWithGZIP(meta['srcFilePath'], meta['tmpDir']);
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'tmp'));
const result = await SnowflakeFileUtil.compressFileWithGZIP(meta['srcFilePath'], tmpDir);

meta['tmpDir'] = tmpDir;
meta['realSrcFilePath'] = result.name;
}
const result = await SnowflakeFileUtil.getDigestAndSizeForFile(meta['realSrcFilePath']);
Expand All @@ -378,25 +380,28 @@
meta['errorDetails'] = err.toString();
meta['errorDetails'] += ` file=${meta['srcFileName']}, real file=${meta['realSrcFilePath']}`;
} finally {
// Remove all files inside tmp folder
const matchingFileNames = getMatchingFilePaths(meta['tmpDir'], meta['srcFileName'] + '*');
for (const matchingFileName of matchingFileNames) {
await new Promise((resolve, reject) => {
fs.unlink(matchingFileName, err => {
if (err) {
reject(err);
}
resolve();

// Remove all files inside tmp folder if compression is set
if (meta['requireCompress']) {
const matchingFileNames = glob.sync(path.join(meta['tmpDir'], meta['srcFileName'] + '*'));

Check failure on line 386 in lib/file_transfer_agent/file_transfer_agent.js

View workflow job for this annotation

GitHub Actions / Run lint

'glob' is not defined
for (const matchingFileName of matchingFileNames) {
await new Promise((resolve, reject) => {
fs.unlink(matchingFileName, err => {
if (err) {
reject(err);
}
resolve();
});
});
});
}
// Delete tmp folder
fs.rmdir(meta['tmpDir'], (err) => {
if (err) {
throw (err);
}
// Delete tmp folder
fs.rmdir(meta['tmpDir'], (err) => {
if (err) {
throw (err);
}

});
});
}
}

return meta;
Expand Down Expand Up @@ -562,7 +567,7 @@
const quoteIndex = command.substring(startIndex).indexOf('\'');
let endIndex = spaceIndex;
if (quoteIndex !== -1 && quoteIndex < spaceIndex) {
endIndex = quoteIndex;
endIndex = quoteIndex;
}
const filePath = command.substring(startIndex, startIndex + endIndex);
return filePath;
Expand Down Expand Up @@ -757,7 +762,7 @@
if (sourceCompression === 'auto_detect') {
autoDetect = true;

} else if (sourceCompression === typeof('undefined')) {
} else if (sourceCompression === typeof ('undefined')) {
autoDetect = false;
} else {
userSpecifiedSourceCompression = fileCompressionType.lookupByMimeSubType(sourceCompression);
Expand Down Expand Up @@ -838,6 +843,6 @@
}

//TODO SNOW-992387: Create a function to renew expired client
function renewExpiredClient() {}
function renewExpiredClient() { }

module.exports = FileTransferAgent;
Loading