BusinessCentral.LinterCop icon indicating copy to clipboard operation
BusinessCentral.LinterCop copied to clipboard

Linter Cop: Auto Download setting

Open MikkelJensenECIT opened this issue 10 months ago • 4 comments

I have problems with the auto download feature in VS Code.

I get this error message in VS Code:

Image

When I try to look at the permissions of the new .dll.tmp file this is what it says:

Image

Do you know what the problem might be? Or is a Windows-/Permission-related problem on my side?

MikkelJensenECIT avatar Jan 21 '25 10:01 MikkelJensenECIT

Yes, i am having the same issue like weeks. I have to go to directory to delete old dll while VS Code is closed then re-open to re-download new version. Otherwise i can not update the LinterCop to get new rules or bug fixes etc.

barandeniz avatar Jan 21 '25 10:01 barandeniz

I am running linux so its hard for me to test this myself.

@Arthurvdv Did you have this issue before?

StefanMaron avatar Jan 21 '25 10:01 StefanMaron

I have this issue, since about a month, but not always. I think that this issue occurs when I restart one VS Code window, but still have other VS Code windows open.

When I start fresh with one VS Code window then there doesn't seem to be this error.

pri-kise avatar Jan 21 '25 10:01 pri-kise

Image

I believe it depends if the AL language server is already up-and-running, where then the BusinessCentral.LinterCop.dll file is locked and can not be changed. I only get this error if I open al AL project/workspace, where opening a blank VS Code Window or a non-AL project/workspace works without any issues.

Maybe it could help to check if the file is locked before executing the rename action, something like this below? 🤔

const fs = require('fs');
const path = require('path');

/**
 * Checks if a file is locked by attempting to open it for writing.
 * @param {string} filePath - The path to the file to check.
 * @returns {Promise<boolean>} - Resolves `true` if the file is locked, otherwise `false`.
 */
async function isFileLocked(filePath) {
  return new Promise((resolve) => {
    const stream = fs.createWriteStream(filePath, { flags: 'r+' });

    stream.on('open', () => {
      stream.close();
      resolve(false); // File is not locked
    });

    stream.on('error', (err) => {
      if (err.code === 'EBUSY' || err.code === 'EACCES' || err.code === 'EPERM') {
        resolve(true); // File is locked
      } else {
        resolve(false); // Some other error occurred
      }
    });
  });
}

// Example usage:
const filePath = path.resolve(__dirname, 'example.txt');

isFileLocked(filePath).then((locked) => {
  if (locked) {
    console.log('File is locked by another process.');
  } else {
    console.log('File is not locked. You can proceed.');
  }
});

The icing on the cake would be to show an message if the file is locked: A new version of LinterCop is ready to be installed. To proceed with the update: Close all open VS Code instances and open a new (empty) window in VS Code. Once you've done this, the update will be applied automatically.

Arthurvdv avatar Jan 22 '25 10:01 Arthurvdv