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

Deletion failed, (OS Error: The system cannot find the path specified. , errno = 3) #144140

Open
nirgranth opened this issue Feb 26, 2024 · 26 comments
Labels
c: crash Stack traces logged to the console P2 Important issues not at the top of the work list team-tool Owned by Flutter Tool team tool Affects the "flutter" command-line tool. See also t: labels. triaged-tool Triaged by Flutter Tool team

Comments

@nirgranth
Copy link

nirgranth commented Feb 26, 2024

Steps to reproduce

run flutter pub cache clean

Expected results

success

Actual results

flutter pub cache clean
This will remove everything inside C:\Users\Nixos\AppData\Local\Pub\Cache.
You will have to run flutter pub get again in each project.
Are you sure? (y/N)? y
Removing pub cache directory C:\Users\Nixos\AppData\Local\Pub\Cache.
Deletion failed, path = 'C:\Users\Nixos\AppData\Local\Pub\Cache' (OS Error: The system cannot find the path specified.
, errno = 3)

Flutter Doctor output

flutter doctor -v

[✓] Flutter (Channel stable, 3.19.0, on Microsoft Windows [Version 10.0.22631.3155], locale en-IN)
    • Flutter version 3.19.0 on channel stable at D:\Flutter\flutter\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision bae5e49bc2 (13 days ago), 2024-02-13 17:46:18 -0800
    • Engine revision 04817c99c9
    • Dart version 3.3.0
    • DevTools version 2.31.1

[✓] Windows Version (Installed version of Windows is version 10 or higher)

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at D:\Android
    • Platform android-VanillaIceCream, build-tools 34.0.0
    • ANDROID_HOME = D:\Android
    • Java binary at: D:\Android\Android Studio\jbr\bin\java
    • Java version OpenJDK Runtime Environment (build 17.0.7+0-b2043.56-10550314)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[✓] Visual Studio - develop Windows apps (Visual Studio Build Tools 2022 17.8.6)
    • Visual Studio at D:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools
    • Visual Studio Build Tools 2022 version 17.8.34525.116
    • Windows 10 SDK version 10.0.22621.0

[✓] Android Studio (version 2023.1)
    • Android Studio at D:\Android\Android Studio
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.7+0-b2043.56-10550314)

[✓] Connected device (5 available)
    • CPH2487 (mobile)  • 192.168.0.175:5555 • android-arm64  • Android 13 (API 33)
    • SM A135F (mobile) • 192.168.0.200:5555 • android-arm    • Android 14 (API 34)
    • Windows (desktop) • windows            • windows-x64    • Microsoft Windows [Version 10.0.22631.3155]
    • Chrome (web)      • chrome             • web-javascript • Google Chrome 121.0.6167.161
    • Edge (web)        • edge               • web-javascript • Microsoft Edge 120.0.2210.91

[✓] Network resources
    • All expected network resources are available.

• No issues found!
@dam-ease dam-ease added the in triage Presently being triaged by the triage team label Feb 26, 2024
@dam-ease
Copy link

Hello @nixos-s
Kindly check out the suggested solutions at #106953 to see if they help.

@dam-ease dam-ease added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Feb 26, 2024
@nirgranth
Copy link
Author

Hello @nixos-s
Kindly check out the suggested solutions at #106953 to see if they help.

Already tried dint work

You can see my comment on it
I open this as that one was closed but the bug re-occurred on the new version too.

@github-actions github-actions bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Feb 26, 2024
@dam-ease
Copy link

Thanks for your response @nixos-s.
I missed out on your response seeing the issue was closed as solved.
Can't see similar issues open currently, I'll be labelling this for more insights from the team.

@dam-ease dam-ease added c: crash Stack traces logged to the console tool Affects the "flutter" command-line tool. See also t: labels. team-tool Owned by Flutter Tool team and removed in triage Presently being triaged by the triage team labels Feb 27, 2024
@nirgranth
Copy link
Author

nirgranth commented Feb 27, 2024

Addional info

Flutter is in D: Drive

 flutter clean
Deleting build...                                                  30.8s
Deleting .dart_tool...                                              44ms
Deleting Generated.xcconfig...                                       0ms
Deleting flutter_export_environment.sh...                            0ms
Deleting .flutter-plugins-dependencies...                            0ms
Deleting .flutter-plugins...                                         2ms
 flutter pub cache clean
This will remove everything inside C:\Users\Nixos\AppData\Local\Pub\Cache.
You will have to run `flutter pub get` again in each project.
Are you sure? (y/N)? y
Removing pub cache directory C:\Users\Nixos\AppData\Local\Pub\Cache.
Deletion failed, path = 'C:\Users\Nixos\AppData\Local\Pub\Cache' (OS Error: The system cannot find the path specified.
, errno = 3)

@christopherfujino christopherfujino self-assigned this Feb 27, 2024
@christopherfujino
Copy link
Member

assigning to myself to investigate where in the stack this is coming from

@christopherfujino
Copy link
Member

I'm fairly sure that this is an upstream pub issue, so I filed: dart-lang/pub#4155. However, I will leave this issue open for discoverability.

@christopherfujino christopherfujino added triaged-tool Triaged by Flutter Tool team P2 Important issues not at the top of the work list labels Feb 27, 2024
@christopherfujino christopherfujino removed their assignment Feb 27, 2024
@sigurdm
Copy link
Contributor

sigurdm commented Feb 29, 2024

This is mysterious to me. cache clean just removes a directory by calling the dart:io primitives.

https://github.com/dart-lang/pub/blob/f5fa122215923a8216335842ba41c3d820a8d4b7/lib/src/system_cache.dart#L305
https://github.com/dart-lang/pub/blob/f5fa122215923a8216335842ba41c3d820a8d4b7/lib/src/io.dart#L472

@nixos-s could you try running flutter pub cache clean -v and attach the log?
@nixos-s can you remove the C:\Users\Nixos\AppData\Local\Pub\Cache dir manually?

Could you also try running dart pub cache clean -v and attach the log?

@nirgranth
Copy link
Author

nirgranth commented Feb 29, 2024

 flutter pub cache clean -v
[ +161 ms] Artifact Instance of 'AndroidGenSnapshotArtifacts' is not required, skipping update.
[   +1 ms] Artifact Instance of 'AndroidInternalBuildArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IOSEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterWebSdk' is not required, skipping update.
[        ] Artifact Instance of 'LegacyCanvasKitRemover' is not required, skipping update.
[   +2 ms] Artifact Instance of 'WindowsEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerDebugSymbols' is not required, skipping update.
[  +78 ms] Artifact Instance of 'MaterialFonts' is not required, skipping update.
[        ] Artifact Instance of 'GradleWrapper' is not required, skipping update.
[        ] Artifact Instance of 'AndroidGenSnapshotArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'AndroidInternalBuildArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IOSEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterWebSdk' is not required, skipping update.
[        ] Artifact Instance of 'LegacyCanvasKitRemover' is not required, skipping update.
[        ] Artifact Instance of 'FlutterSdk' is not required, skipping update.
[        ] Artifact Instance of 'WindowsEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerDebugSymbols' is not required, skipping update.
[        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FontSubsetArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'PubDependencies' is not required, skipping update.
[  +39 ms] executing: [C:\Users\Nixos/] D:\Flutter\flutter_windows_3.16.9-stable\flutter\bin\cache\dart-sdk\bin\dart pub --suppress-analytics cache clean -v
FINE: Pub 3.2.6
FINE: Showing confirm message: This will remove everything inside C:\Users\Nixos\AppData\Local\Pub\Cache.
    | You will have to run `flutter pub get` again in each project.
    | Are you sure?
This will remove everything inside C:\Users\Nixos\AppData\Local\Pub\Cache.
You will have to run `flutter pub get` again in each project.
Are you sure? (y/N)? y
MSG : Removing pub cache directory C:\Users\Nixos\AppData\Local\Pub\Cache.
IO  : Deleting directory C:\Users\Nixos\AppData\Local\Pub\Cache.
ERR : Deletion failed, path = 'C:\Users\Nixos\AppData\Local\Pub\Cache' (OS Error: The system cannot find the path specified.
    | , errno = 3)
FINE: Exception type: PathNotFoundException
FINE: dart:io                                                FileSystemEntity.deleteSync
    | package:pub/src/io.dart 471:23                         deleteEntry.<fn>
    | package:pub/src/io.dart 442:16                         _attempt
    | package:pub/src/io.dart 465:3                          deleteEntry
    | package:pub/src/system_cache.dart 306:5                SystemCache.clean
    | package:pub/src/command/cache_clean.dart 36:15         CacheCleanCommand.runProtected
    | ===== asynchronous gap ===========================
    | dart:async                                             Future.catchError
    | package:pub/src/utils.dart 135:10                      captureErrors.wrappedCallback
    | package:stack_trace                                    Chain.capture
    | package:pub/src/utils.dart 150:11                      captureErrors
    | package:pub/src/command.dart 198:13                    PubCommand.run
    | package:args/command_runner.dart 212:27                CommandRunner.runCommand
    | package:dartdev/dartdev.dart 240:30                    DartdevRunner.runCommand
    | package:args/command_runner.dart 122:25                CommandRunner.run.<fn>
    | dart:async                                             new Future.sync
    | package:args/command_runner.dart 122:14                CommandRunner.run
    | package:dartdev/dartdev.dart 59:29                     runDartdev
    | C:\b\s\w\ir\x\w\sdk\pkg\dartdev\bin\dartdev.dart 11:9  main
---- Log transcript ----
FINE: Pub 3.2.6
FINE: Showing confirm message: This will remove everything inside C:\Users\Nixos\AppData\Local\Pub\Cache.
    | You will have to run `flutter pub get` again in each project.
    | Are you sure?
MSG : Removing pub cache directory C:\Users\Nixos\AppData\Local\Pub\Cache.
IO  : Deleting directory C:\Users\Nixos\AppData\Local\Pub\Cache.
ERR : Deletion failed, path = 'C:\Users\Nixos\AppData\Local\Pub\Cache' (OS Error: The system cannot find the path specified.
    | , errno = 3)
FINE: Exception type: PathNotFoundException
FINE: dart:io                                                FileSystemEntity.deleteSync
    | package:pub/src/io.dart 471:23                         deleteEntry.<fn>
    | package:pub/src/io.dart 442:16                         _attempt
    | package:pub/src/io.dart 465:3                          deleteEntry
    | package:pub/src/system_cache.dart 306:5                SystemCache.clean
    | package:pub/src/command/cache_clean.dart 36:15         CacheCleanCommand.runProtected
    | ===== asynchronous gap ===========================
    | dart:async                                             Future.catchError
    | package:pub/src/utils.dart 135:10                      captureErrors.wrappedCallback
    | package:stack_trace                                    Chain.capture
    | package:pub/src/utils.dart 150:11                      captureErrors
    | package:pub/src/command.dart 198:13                    PubCommand.run
    | package:args/command_runner.dart 212:27                CommandRunner.runCommand
    | package:dartdev/dartdev.dart 240:30                    DartdevRunner.runCommand
    | package:args/command_runner.dart 122:25                CommandRunner.run.<fn>
    | dart:async                                             new Future.sync
    | package:args/command_runner.dart 122:14                CommandRunner.run
    | package:dartdev/dartdev.dart 59:29                     runDartdev
    | C:\b\s\w\ir\x\w\sdk\pkg\dartdev\bin\dartdev.dart 11:9  main
---- End log transcript ----
IO  : Writing 2749 characters to text file C:\Users\Nixos\AppData\Local\Pub\Cache\log\pub_log.txt.
MSG : Logs written to C:\Users\Nixos\AppData\Local\Pub\Cache\log\pub_log.txt.
[pub_log.txt](https://github.com/flutter/flutter/files/14450071/pub_log.txt)
[+9595 ms] pub failed
                    command: "D:\Flutter\flutter_windows_3.16.9-stable\flutter\bin\cache\dart-sdk\bin\dart pub --suppress-analytics cache clean -v"
                    pub env: {
                      "FLUTTER_ROOT": "D:\Flutter\flutter_windows_3.16.9-stable\flutter",
                      "PUB_ENVIRONMENT": "flutter_cli:forward",
                    }
                    exit code: 66

[   +8 ms] "flutter cache" took 9,741ms.
[   +2 ms]
           #0      throwToolExit (package:flutter_tools/src/base/common.dart:10:3)
           #1      _DefaultPub._runWithStdioInherited (package:flutter_tools/src/dart/pub.dart:447:7)
           <asynchronous suspension>
           #2      _DefaultPub.interactively (package:flutter_tools/src/dart/pub.dart:530:5)
           <asynchronous suspension>
           #3      PackagesForwardCommand.runCommand (package:flutter_tools/src/commands/packages.dart:136:5)
           <asynchronous suspension>
           #4      FlutterCommand.run.<anonymous closure> (package:flutter_tools/src/runner/flutter_command.dart:1367:27)
           <asynchronous suspension>
           #5      AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
           <asynchronous suspension>
           #6      CommandRunner.runCommand (package:args/command_runner.dart:212:13)
           <asynchronous suspension>
           #7      FlutterCommandRunner.runCommand.<anonymous closure> (package:flutter_tools/src/runner/flutter_command_runner.dart:348:9)
           <asynchronous suspension>
           #8      AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
           <asynchronous suspension>
           #9      FlutterCommandRunner.runCommand (package:flutter_tools/src/runner/flutter_command_runner.dart:294:5)
           <asynchronous suspension>
           #10     run.<anonymous closure>.<anonymous closure> (package:flutter_tools/runner.dart:112:9)
           <asynchronous suspension>
           #11     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
           <asynchronous suspension>
           #12     main (package:flutter_tools/executable.dart:90:3)
           <asynchronous suspension>


[   +3 ms] Running 0 shutdown hooks
[        ] Shutdown hooks complete
[   +4 ms] exiting with code 66

can you remove the C:\Users\Nixos\AppData\Local\Pub\Cache dir manually?

Yes

dart pub cache clean -v
FINE: Pub 3.2.6
FINE: Showing confirm message: This will remove everything inside C:\Users\Nixos\AppData\Local\Pub\Cache.
    | You will have to run `dart pub get` again in each project.
    | Are you sure?
This will remove everything inside C:\Users\Nixos\AppData\Local\Pub\Cache.
You will have to run `dart pub get` again in each project.
Are you sure? (y/N)? y
MSG : Removing pub cache directory C:\Users\Nixos\AppData\Local\Pub\Cache.
IO  : Deleting directory C:\Users\Nixos\AppData\Local\Pub\Cache.
ERR : Deletion failed, path = 'C:\Users\Nixos\AppData\Local\Pub\Cache' (OS Error: The system cannot find the path specified.
    | , errno = 3)
FINE: Exception type: PathNotFoundException
FINE: dart:io                                                FileSystemEntity.deleteSync
    | package:pub/src/io.dart 471:23                         deleteEntry.<fn>
    | package:pub/src/io.dart 442:16                         _attempt
    | package:pub/src/io.dart 465:3                          deleteEntry
    | package:pub/src/system_cache.dart 306:5                SystemCache.clean
    | package:pub/src/command/cache_clean.dart 36:15         CacheCleanCommand.runProtected
    | ===== asynchronous gap ===========================
    | dart:async                                             Future.catchError
    | package:pub/src/utils.dart 135:10                      captureErrors.wrappedCallback
    | package:stack_trace                                    Chain.capture
    | package:pub/src/utils.dart 150:11                      captureErrors
    | package:pub/src/command.dart 198:13                    PubCommand.run
    | package:args/command_runner.dart 212:27                CommandRunner.runCommand
    | package:dartdev/dartdev.dart 240:30                    DartdevRunner.runCommand
    | package:args/command_runner.dart 122:25                CommandRunner.run.<fn>
    | dart:async                                             new Future.sync
    | package:args/command_runner.dart 122:14                CommandRunner.run
    | package:dartdev/dartdev.dart 59:29                     runDartdev
    | C:\b\s\w\ir\x\w\sdk\pkg\dartdev\bin\dartdev.dart 11:9  main
---- Log transcript ----
FINE: Pub 3.2.6
FINE: Showing confirm message: This will remove everything inside C:\Users\Nixos\AppData\Local\Pub\Cache.
    | You will have to run `dart pub get` again in each project.
    | Are you sure?
MSG : Removing pub cache directory C:\Users\Nixos\AppData\Local\Pub\Cache.
IO  : Deleting directory C:\Users\Nixos\AppData\Local\Pub\Cache.
ERR : Deletion failed, path = 'C:\Users\Nixos\AppData\Local\Pub\Cache' (OS Error: The system cannot find the path specified.
    | , errno = 3)
FINE: Exception type: PathNotFoundException
FINE: dart:io                                                FileSystemEntity.deleteSync
    | package:pub/src/io.dart 471:23                         deleteEntry.<fn>
    | package:pub/src/io.dart 442:16                         _attempt
    | package:pub/src/io.dart 465:3                          deleteEntry
    | package:pub/src/system_cache.dart 306:5                SystemCache.clean
    | package:pub/src/command/cache_clean.dart 36:15         CacheCleanCommand.runProtected
    | ===== asynchronous gap ===========================
    | dart:async                                             Future.catchError
    | package:pub/src/utils.dart 135:10                      captureErrors.wrappedCallback
    | package:stack_trace                                    Chain.capture
    | package:pub/src/utils.dart 150:11                      captureErrors
    | package:pub/src/command.dart 198:13                    PubCommand.run
    | package:args/command_runner.dart 212:27                CommandRunner.runCommand
    | package:dartdev/dartdev.dart 240:30                    DartdevRunner.runCommand
    | package:args/command_runner.dart 122:25                CommandRunner.run.<fn>
    | dart:async                                             new Future.sync
    | package:args/command_runner.dart 122:14                CommandRunner.run
    | package:dartdev/dartdev.dart 59:29                     runDartdev
    | C:\b\s\w\ir\x\w\sdk\pkg\dartdev\bin\dartdev.dart 11:9  main
---- End log transcript ----
IO  : Writing 2725 characters to text file C:\Users\Nixos\AppData\Local\Pub\Cache\log\pub_log.txt.
MSG : Logs written to C:\Users\Nixos\AppData\Local\Pub\Cache\log\pub_log.txt.

pub_log.txt

@nirgranth
Copy link
Author

To note i have downgraded to flutter 3.16.9

It still faces same issues as 3.19.0

Logs are from 3.16.9

@sigurdm
Copy link
Contributor

sigurdm commented Mar 4, 2024

Thanks for the added details.

Hmm, I'm dumbstruck by this behavior. No clue what could be happening - the code does check for the dir's existence up front - and the error message says "path not found". We have tests running this code on Windows in CI.

@jonasfj do you have any ideas?

@jonasfj
Copy link
Member

jonasfj commented Mar 4, 2024

@sigurdm are we handling PathNotFoundException ?

It sounds to me like the PUB_CACHE was deleted, nothing exists at C:\Users\Nixos\AppData\Local\Pub\Cache, and thus, deletion fails.

@nixos-s for context, the PUB_CACHE used to be in FLUTTER_ROOT. But we changed to exist in the users home directory, so that it doesn't get purged between flutter installs.
This also means it can be shared between different flutter / dart installs, this is important since things like dart pub global activate won't work nicely otherwise.

This is why even if you installed flutter on D:, that's not where the PUB_CACHE is located.

Does the C:\Users\Nixos\AppData\Local\Pub\Cache exist on your system?

@nirgranth
Copy link
Author

Yes the dir is there, I have to delete it manually to get rid of it

@jonasfj
Copy link
Member

jonasfj commented Mar 4, 2024

@nixos-s does the issue reproduce after you've deleted it manually? Did it just get in a weird state or what?

Are you owner of the directory, have permissions to delete it? things like that.

@nirgranth
Copy link
Author

Yes I am an admin

I have retried with dir being present

And doing pub get and the cache clean after that still leads to same error

I have also tried with admin privileges in terminal

@sigurdm
Copy link
Contributor

sigurdm commented Mar 4, 2024

Just to narrow the possibilities a bit. Could you please run this dart script:

import 'dart:io';

main() {
  print(Directory(r'C:\Users\Nixos\AppData\Local\Pub\Cache').existsSync());
  print(File(r'C:\Users\Nixos\AppData\Local\Pub\Cache').statSync());
  Directory(r'C:\Users\Nixos\AppData\Local\Pub\Cache')
      .deleteSync(recursive: true);
}

And report the output?

@nirgranth
Copy link
Author

dart "d:\Work\Daily Work\a.dart"
true
FileStat: type directory
          changed 2024-02-27 22:41:08.000
          modified 2024-02-29 20:56:27.000
          accessed 2024-03-04 16:12:09.000
          mode rwxrwxrwx
          size 0

@sigurdm
Copy link
Contributor

sigurdm commented Mar 4, 2024

And it deleted the directory?

@nirgranth
Copy link
Author

nirgranth commented Mar 4, 2024

true
FileStat: type directory
          changed 2024-02-27 22:41:08.000
          modified 2024-02-29 20:56:27.000
          accessed 2024-03-04 16:12:09.000
          mode rwxrwxrwx
          size 0
Unhandled exception:
PathNotFoundException: Deletion failed, path = 'C:\Users\Nixos\AppData\Local\Pub\Cache' (OS Error: The system cannot find the path specified.

, errno = 3)
#0      _Directory._deleteSync (dart:io/directory_impl.dart:193:7)
#1      FileSystemEntity.deleteSync (dart:io/file_system_entity.dart:414:7)
#2      main (file:///d:/Work/Daily%20Work/a.dart:7:8)
#3      _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:297:19)
#4      _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)

@nirgranth
Copy link
Author

With help from chatgpt i tried out a few thing
I tried debugging the environment

import 'dart:io';

void main() async {
  var cacheDirectory = Directory(r'C:\Users\Nixos\AppData\Local\Pub\Cache');

  if (cacheDirectory.existsSync()) {
    print('Directory exists: ${cacheDirectory.path}');
    printFileStat(cacheDirectory);

    try {
      await deleteDirectory(cacheDirectory);
      print('Directory deletion scheduled successfully.');
    } catch (e) {
      print('Error scheduling directory deletion: $e');
    }
  } else {
    print('Directory does not exist: ${cacheDirectory.path}');
  }
}

void printFileStat(Directory directory) {
  var fileStat = directory.statSync();
  print('FileStat: type ${fileStat.type}');
  print('changed ${fileStat.changed}');
  print('modified ${fileStat.modified}');
  print('accessed ${fileStat.accessed}');
  print('mode ${fileStat.mode}');
  print('size ${fileStat.size}');
}

Future<void> deleteDirectory(Directory directory) async {
  try {
    await Future.delayed(Duration.zero);
    await directory.delete(recursive: true);
  } catch (e) {
    print('Error during asynchronous deletion: $e');
    rethrow; // Rethrow the error for the caller to handle if needed
  }
}

[Running] dart "C:\Users\Nixos\AppData\Local\Temp\tempCodeRunnerFile.dart"
Directory exists: C:\Users\Nixos\AppData\Local\Pub\Cache
FileStat: type directory
changed 2024-02-27 22:41:08.000
modified 2024-02-29 20:56:27.000
accessed 2024-03-04 23:33:18.000
mode 16895
size 0
Error during asynchronous deletion: PathNotFoundException: Deletion failed, path = 'C:\Users\Nixos\AppData\Local\Pub\Cache' (OS Error: The system cannot find the path specified.

, errno = 3)
Error scheduling directory deletion: PathNotFoundException: Deletion failed, path = 'C:\Users\Nixos\AppData\Local\Pub\Cache' (OS Error: The system cannot find the path specified.

, errno = 3)

Trying via Cmd Works

import 'dart:io';

void main() async {
  var cacheDirectoryPath = r'C:\Users\Nixos\AppData\Local\Pub\Cache';

  try {
    await Process.run('cmd', ['/c', 'rmdir', '/s', '/q', cacheDirectoryPath]);
    print('Directory deleted successfully.');
  } catch (e) {
    print('Error deleting directory: $e');
  }
}
[Done] exited with code=0 in 0.439 seconds

[Running] dart "C:\Users\Nixos\AppData\Local\Temp\tempCodeRunnerFile.dart"
Directory deleted successfully.

@RB-93
Copy link

RB-93 commented Mar 29, 2024

The same issue is found on my Flutter env too.

I have to delete the Cache folder manually.

Command line error:
image

Flutter SDK 3.19.5

@zidanone
Copy link

you need how to fix this issues chack this video is 1 min

the video : https://youtu.be/MbcSYiGthOM
Note : follow the channel and like the video to keep my do more fixed

https://youtu.be/MbcSYiGthOM

@zidanone
Copy link

The same issue is found on my Flutter env too.

I have to delete the Cache folder manually.

Command line error: image

Flutter SDK 3.19.5

chack this video to get fixed 👍
https://youtu.be/MbcSYiGthOM
🥇

@nirgranth
Copy link
Author

you need how to fix this issues chack this video is 1 min

the video : https://youtu.be/MbcSYiGthOM Note : follow the channel and like the video to keep my do more fixed

https://youtu.be/MbcSYiGthOM

i had already tried it this doesn't work

@sigurdm
Copy link
Contributor

sigurdm commented Apr 2, 2024

true
FileStat: type directory
          changed 2024-02-27 22:41:08.000
          modified 2024-02-29 20:56:27.000
          accessed 2024-03-04 16:12:09.000
          mode rwxrwxrwx
          size 0
Unhandled exception:
PathNotFoundException: Deletion failed, path = 'C:\Users\Nixos\AppData\Local\Pub\Cache' (OS Error: The system cannot find the path specified.

, errno = 3)
#0      _Directory._deleteSync (dart:io/directory_impl.dart:193:7)
#1      FileSystemEntity.deleteSync (dart:io/file_system_entity.dart:414:7)
#2      main (file:///d:/Work/Daily%20Work/a.dart:7:8)
#3      _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:297:19)
#4      _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)

From this it looks to me like a dart:io issue. The directory is clearly there, but delete() doesn't find it.

@sortie do you have any insights here?

@sortie
Copy link
Contributor

sortie commented Apr 2, 2024

My best bet is that ERROR_PATH_NOT_FOUND happens during the recursive directory deletion. The error might happen in a context where it should be ignored. Reading runtime/bin/directory_win.cc, for instance what could happen, is that it reads the directory and deletes each directory entry recursively. However, if there is any race condition where another thread makes an entry in the directory and deletes it, then the code doesn't protect against that case. dart may try to remove such a file and it'll be deleted by the time it's gone, failing with ERROR_PATH_NOT_FOUND. It might also be a subdirectory since we don't get ERROR_FILE_NOT_FOUND. The recursive deletion loop should detect these errors and ignore such race conditions, being happy when the directory is finally empty.

Or perhaps there's other conditions in there that might bring up these error codes in a surprising manner. You gotta remember there's lots of background activity on Windows that may keep paths alive or act on them in the background. The path in the exception is added on an outer layer, so it doesn't actually have the relevant failing nested path in the error message. You should audit the dart:io code carefully to spot all the potential cases that can happen, I didn't study it super closely at this time. The issue could be something else.

@sortie
Copy link
Contributor

sortie commented Apr 2, 2024

@brianquinlan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: crash Stack traces logged to the console P2 Important issues not at the top of the work list team-tool Owned by Flutter Tool team tool Affects the "flutter" command-line tool. See also t: labels. triaged-tool Triaged by Flutter Tool team
Projects
None yet
Development

No branches or pull requests

8 participants