Skip to content

Commit

Permalink
remove extra directories
Browse files Browse the repository at this point in the history
  • Loading branch information
joseplayero committed Aug 26, 2024
1 parent 58b9cbe commit 9028b99
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion scripts/downloadOllama.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,22 @@ function setExecutable(filePath) {
});
}

function downloadAndExtractZip(url, extractPath, redirectCount = 0, timeout = 500000) {
function removeDirectory(dirPath) {
if (fs.existsSync(dirPath)) {
fs.readdirSync(dirPath).forEach((file) => {
const curPath = path.join(dirPath, file);
if (fs.lstatSync(curPath).isDirectory()) {
removeDirectory(curPath);
} else {
fs.unlinkSync(curPath);
}
});
fs.rmdirSync(dirPath);
}
}


function downloadAndExtractZip(url, extractPath, redirectCount = 0, timeout = 30000) {
return new Promise((resolve, reject) => {
if (redirectCount > 5) {
reject(new Error("Too many redirects"));
Expand Down Expand Up @@ -78,6 +93,19 @@ function downloadAndExtractZip(url, extractPath, redirectCount = 0, timeout = 50
console.error(`Failed to delete temporary file ${tempPath}: ${unlinkError.message}`);
}
console.log('Extraction completed');

// Windows-specific cleanup
if (process.platform === 'win32') {
console.log('Performing Windows-specific cleanup...');
const cudaPath = path.join(extractPath, 'cuda');
const rocmPath = path.join(extractPath, 'rocm');

removeDirectory(cudaPath);
removeDirectory(rocmPath);

console.log('Cleanup completed');
}

resolve();
});
} catch (error) {
Expand Down Expand Up @@ -118,6 +146,7 @@ function downloadAndExtractZip(url, extractPath, redirectCount = 0, timeout = 50
});
});
}

function downloadFile(url, filePath, redirectCount = 0, timeout = 500000) {
return new Promise((resolve, reject) => {
if (redirectCount > 5) {
Expand Down

0 comments on commit 9028b99

Please sign in to comment.