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

Relative links to directories don't work on Windows #53689

Closed
sgrekhov opened this issue Oct 5, 2023 · 3 comments
Closed

Relative links to directories don't work on Windows #53689

sgrekhov opened this issue Oct 5, 2023 · 3 comments
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. library-io P2 A bug or feature request we're likely to work on

Comments

@sgrekhov
Copy link
Contributor

sgrekhov commented Oct 5, 2023

Link.create() documentation says nothing special about relative links on Windows. So, seems, that they should work. But they don't. For example, the tests below works well on Linux but fails on Windows

import "dart:io";

main() async {
  Directory sandbox = Directory.systemTemp.createTempSync();
  try {
    Directory target =
      new Directory(sandbox.path + Platform.pathSeparator + "dir1");
    target.createSync();
    Link link = new Link(sandbox.path + Platform.pathSeparator + "link.lnk");
    await link.create("dir1").then((Link created) {
      print(created.targetSync()); // Linux: dir1, Windows: dir1
      print(FileSystemEntity.typeSync(created.path)); // Linux: directory, Windows: link
      print(created.resolveSymbolicLinksSync()); // Linux: /tmp/PRVKQP/dir1, Windows: FileSystemException: Cannot resolve symbolic links, path = 'C:\Users\sgrek\AppData\Local\Temp\aba06b27\link.lnk' (OS Error: Access denied , errno = 5)
    });
  } finally {
    sandbox.deleteSync(recursive: true);
  }
}

On Windows, Link pointing to a not existing entity has type link (see #53684 (comment)). So, exception is, probably, also caused by the fact that relative link on Windows cannot find its target. Anyway, please fix it or document that relative links on Windows not supported or have some limitations

Probably this is the same issue as #45981

Tested on Dart SDK version: 3.2.0-228.0.dev (dev) (Tue Oct 3 21:02:12 2023 -0700) on "windows_x64"

@sgrekhov sgrekhov added area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-io labels Oct 5, 2023
@sgrekhov sgrekhov changed the title Relative links don't work on Windows Relative links to directories don't work on Windows Oct 5, 2023
@sgrekhov
Copy link
Contributor Author

sgrekhov commented Oct 5, 2023

Issue exists for directories only (changed title accordingly). Test below works well on both Windows and Linux

import "dart:io";

main() async {
  Directory sandbox = Directory.systemTemp.createTempSync();
  try {
    File target =
      new File(sandbox.path + Platform.pathSeparator + "file.txt");
    target.createSync();
    Link link = new Link(sandbox.path + Platform.pathSeparator + "link.lnk");
    await link.create("file.txt").then((Link created) {
      print(created.targetSync()); // Linux: file.txt, Windows: file.txt
      print(FileSystemEntity.typeSync(created.path)); // Linux: file, Windows: file
      print(created.resolveSymbolicLinksSync()); // Linux: /tmp/XNQSRN/file.txt, Windows: C:\Users\sgrek\AppData\Local\Temp\fd9d7667\file.txt
      // Now create a directory and move the link to it. Its relative path
      // should point to a not existing entity after it
      Directory dir = sandbox.createTempSync();
      Link moved =
        created.renameSync(dir.path + Platform.pathSeparator + "moved.lnk");
      print(moved.targetSync()); // Linux: file.txt, Windows: file.txt
      print(FileSystemEntity.typeSync(moved.path));  // Linux: notFound, Windows: link
    });
  } finally {
    sandbox.deleteSync(recursive: true);
  }
}

@brianquinlan brianquinlan added the P2 A bug or feature request we're likely to work on label Nov 2, 2023
@lrhn lrhn added area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. and removed area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. labels Apr 21, 2024
@brianquinlan
Copy link
Contributor

I can't reproduce this. The output using Dart 3.4.0 is:

dir1
directory
C:\Users\brian\AppData\Local\Temp\d89223bb\dir1

Possibly this was fixed in 097c84f ?

If these tests are disabled in co19, could you try to reenable them and see if they still fail?

@sgrekhov
Copy link
Contributor Author

sgrekhov commented Aug 12, 2024

Yes, the issue was fixed in 097c84f and appropriate co19 tests were updated accordingly.
See dart-lang/co19@d04448a and dart-lang/co19@3011a2e. So, I believe, this issue can be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. library-io P2 A bug or feature request we're likely to work on
Projects
None yet
Development

No branches or pull requests

3 participants