message: Refactor cleanGlob to make it more readable
diff: @@ -37,7 +37,7 @@ export class Cleaner {
  }
  }
  - private cleanGlob(rootFile: string): Promise<void> {
  + private async cleanGlob(rootFile: string): Promise<void> {
  const configuration = vscode.workspace.getConfiguration('latex-workshop')
  let globs = configuration.get('latex.clean.fileTypes') as string[]
  const outdir = path.resolve(path.dirname(rootFile), this.extension.manager.getOutDir(rootFile))
  @@ -45,50 +45,27 @@ export class Cleaner {
  globs = globs.map(globType => './**/' + globType)
  }
  - return Promise.all(
  - // Get an array of arrays containing all the files found by the globs
  - globs.map(g => this.globP(g, {cwd: outdir}))
  - ).then(files => files
  + const files = globs.map(g => glob.sync(g, {cwd: outdir}))
  // Reduce the array of arrays to a single array containing all the files that should be deleted
  .reduce((all, curr) => all.concat(curr), [])
  // Resolve the absolute filepath for every file
  .map(file => path.resolve(outdir, file))
  - ).then(files => Promise.all(
  - // Try to unlink the files, returning a Promise for every file
  - files.map(file => {
  + for (const file of files) {
  const stats: fs.Stats = fs.statSync(file)
  if (stats.isFile()) {
  - fs.promises.unlink(file).then(() => {
  - this.extension.logger.addLogMessage(`File cleaned: ${file}`)
  - }, () => {
  - this.extension.logger.addLogMessage(`Error removing file: ${file}`)
  - })
  - } else {
  - this.extension.logger.addLogMessage(`Not removing non-file: ${file}`)
  - }
  - })
  - )).then(
  - () => { } // Do not pass results to Promise returned by clean()
  - ).catch(err => {
  - this.extension.logger.addLogMessage(`Error during deletion of files: ${err}`)
  + try {
  + await fs.promises.unlink(file)
  + this.extension.logger.addLogMessage(`Cleaning file: ${file}`)
  + } catch (err) {
  + this.extension.logger.addLogMessage(`Error cleaning file: ${file}`)
  if (err instanceof Error) {
  this.extension.logger.logError(err)
  }
  - })
  }
  -
  - // This function wraps the glob package into a promise.
  - // It behaves like the original apart from returning a Promise instead of requiring a Callback.
  - private globP(pattern: string, options: glob.IOptions): Promise<string[]> {
  - return new Promise((resolve, reject) => {
  - glob(pattern, options, (err, files) => {
  - if (err) {
  - reject(err)
  } else {
  - resolve(files)
  + this.extension.logger.addLogMessage(`Not removing non-file: ${file}`)
  + }
  }
  - })
  - })
  }
  private cleanCommand(rootFile: string): Promise<void> {
  