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: Create Output folder for HasContentChanged #170

Merged
merged 1 commit into from
Oct 28, 2024
Merged
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
21 changes: 13 additions & 8 deletions consumer-server/src/logic/has-content-changed-task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Entity } from '@dcl/schemas'
import * as fs from 'fs'
import * as path from 'path'
import fetch from 'node-fetch'
import { ILoggerComponent } from '@well-known-components/interfaces' // Assuming you're using the node-fetch package
import { ILoggerComponent } from '@well-known-components/interfaces'
async function getActiveEntity(ids: string, contentServer: string): Promise<Entity> {
const url = `${contentServer}/entities/active`

Expand Down Expand Up @@ -110,6 +110,8 @@ async function downloadFilesFromManifestSuccesfully(
env: string,
logger: ILoggerComponent.ILogger
): Promise<boolean> {
fs.mkdirSync(outputFolder, { recursive: true })

const baseUrl = `https://ab-cdn.decentraland.${env}/${version}/${previousHash}/`

for (const file of hashesToDownload) {
Expand Down Expand Up @@ -138,14 +140,17 @@ async function downloadFilesFromManifestSuccesfully(
}

// Helper function to delete all files in the output folder
async function DeleteFilesInOutputFolder(outputFolder: string): Promise<void> {
async function DeleteFilesInOutputFolder(outputFolder: string, logger: ILoggerComponent.ILogger): Promise<void> {
if (fs.existsSync(outputFolder)) {
const files = fs.readdirSync(outputFolder)

for (const file of files) {
const filePath = path.join(outputFolder, file)
fs.unlinkSync(filePath) // Delete each file
// Delete the directory and all of its contents
try {
fs.rmSync(outputFolder, { recursive: true, force: true })
logger.log(`HasContentChanged: Directory ${path} deleted successfully`)
} catch (err) {
logger.log(`HasContentChanged: Error deleting ${path} ${err}`)
}
} else {
logger.log(`HasContentChanged: Directory ${path} does not exist`)
}
}

Expand Down Expand Up @@ -190,7 +195,7 @@ export async function hasContentChange(
return false
} else {
logger.info(`HasContentChanged Error: Some files failed to download`)
await DeleteFilesInOutputFolder(outputFolder)
await DeleteFilesInOutputFolder(outputFolder, logger)
}
} else {
logger.info(`HasContentChanged Error: Not all entities contained in old manifest`)
Expand Down
Loading