Coder Social home page Coder Social logo

Comments (5)

dsherret avatar dsherret commented on July 27, 2024

Do you see the directory in Deno.env.get("PATH")? What’s the extension of winget? Do you see that extension in Deno.env.get("PATHEXT")?

from dax.

xe54ck avatar xe54ck commented on July 27, 2024

The directory does appear. The extension is exe.

PS C:\> cmd /c where winget
C:\Users\user\AppData\Local\Microsoft\WindowsApps\winget.exe

PS C:\> which winget
/c/Users/user/AppData/Local/Microsoft/WindowsApps/winget

C:\Users\user\AppData\Local\Microsoft\WindowsApps is on the path.

After inspecting the WindowsApps directory, it appears winget.exe is a symlink into another directory. This seems to be the common for applications installed by Windows Apps (winget is installed this way).

MINGW64 ~/AppData/Local/Microsoft/WindowsApps
$ ls -al
total 24
...
lrwxrwxrwx 1 user 197609 101 Mar 28 15:55 winget.exe -> '/c/Program Files/WindowsApps/Microsoft.DesktopAppInstaller_1.19.10173.0_x64__8wekyb3d8bbwe/winget.exe'*
lrwxrwxrwx 1 user 197609  93 Feb 15 10:37 wt.exe -> '/c/Program Files/WindowsApps/Microsoft.WindowsTerminal_1.16.10262.0_x64__8wekyb3d8bbwe/wt.exe'*
...

If I add the symlinked path directly to %PATH%, it does work. The issue is maybe the symlink?

from dax.

dsherret avatar dsherret commented on July 27, 2024

Thanks for investigating! Yeah it appears deno_which needs to handle symlinks.

from dax.

xe54ck avatar xe54ck commented on July 27, 2024

Looks like updating deno_which's fileExists and fileExistsSync functions to use Deno.lstat resolves the issue.

Updated deno_which mod.ts:

  async fileExists(path: string): Promise<boolean> {
    try {
      const result = await Deno.lstat(path);
      return result.isFile;
    } catch (err) {
      if (err instanceof Deno.errors.PermissionDenied) {
        throw err;
      }
      return false;
    }
  }

  fileExistsSync(path: string): boolean {
    try {
      const result = Deno.lstatSync(path);
      return result.isFile;
    } catch (err) {
      if (err instanceof Deno.errors.PermissionDenied) {
        throw err;
      }
      return false;
    }
  }

The Deno docs state that Deno.stat Will always follow symlinks but that does not appear to be the case. For example, this simple code errors:

try {
   const stat = await Deno.stat(`C:/Users/user/AppData/Local/Microsoft/WindowsApps/winget.EXE`)
   console.log(stat)
} catch (e) {
   console.log(e)
}
Error: The file cannot be accessed by the system. (os error 1920): stat 'C:/Users/user/AppData/Local/Microsoft/WindowsApps/winget.EXE'
    at async Object.stat (ext:deno_fs/30_fs.js:323:15)
    at async file:///C:/Development/deno_which/test.ts:4:14

Is this a bug in Deno.stat or weird issue with Windows symlinks?

from dax.

dsherret avatar dsherret commented on July 27, 2024

I investigated and opened denoland/deno#18598

This is not a deno_which issue.

from dax.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.