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

Wrong 'output' path #2342

Open
ewwink opened this issue Mar 15, 2024 · 2 comments
Open

Wrong 'output' path #2342

ewwink opened this issue Mar 15, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@ewwink
Copy link

ewwink commented Mar 15, 2024

Describe your issue

epg directory

/home/epg

command

cd /home/epg
npm run grab -- --site=indihometv.com -o /download/xml/id.xml

the file should be downloaded to /download/xml/id.xml but it saved to /home/epg/download/xml/id.xml

@ewwink ewwink added the bug Something isn't working label Mar 15, 2024
@demod-au
Copy link

thanks.. you helped me find where they were going. I have shortened my path to accommodate the problem.

@AndMetal
Copy link

AndMetal commented Mar 23, 2024

I believe this is an issue with how Storage is being used in guide.ts.

In the constructor, Storage is called with no arguments:

constructor({ channels, programs, logger, filepath, gzip }: GuideProps) {
this.channels = channels
this.programs = programs
this.logger = logger
this.storage = new Storage()
this.filepath = filepath
this.gzip = gzip || false
}

Looking at the code for @freearhey/core (src/storage.ts), if a root directory path is passed it is used, otherwise it uses the current working directory:

  constructor(rootDir?: string) {
    this._rootDir = rootDir ? path.resolve(rootDir) : process.cwd()
  }

When the save call is made:

const xmlFilepath = this.filepath
this.logger.info(` saving to "${xmlFilepath}"...`)
await this.storage.save(xmlFilepath, xmltv.toString())
if (this.gzip) {
const zip = new Zip()
const compressed = await zip.compress(xmltv.toString())
const gzFilepath = `${this.filepath}.gz`
this.logger.info(` saving to "${gzFilepath}"...`)
await this.storage.save(gzFilepath, compressed)
}

it gets mapped to _write in Storage which adds the path to the root directory:

  async _write(filepath: string, data: any = ''): Promise<void> {
    const absFilepath = path.join(this._rootDir, filepath)
    const dir = path.dirname(absFilepath)

    await this.createDir(dir)
    await fs.writeFile(absFilepath, data, { encoding: 'utf8', flag: 'w' })
  }

which is the working directory the script was called from.

I believe the fix would be to utilize Path in @freearhey/core to get the dirname of the output option and pass that to the Storage constructor. From what I can tell if it is just a filename/pattern or references a relative path it should default to the current working directory as a base, so in theory it should be mostly backwards compatible.

Edit: as a workaround you might be able to use ../../download/xml/id.xml for the output option.

Edit 2: I confirmed ../../download/xml/id.xml works to put the file into that other directory. I still think absolute paths should be allowable and handled like I mentioned above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

No branches or pull requests

3 participants