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

Exception thrown on Windows if file already exists #89

Open
cjhines opened this issue Nov 25, 2024 · 1 comment
Open

Exception thrown on Windows if file already exists #89

cjhines opened this issue Nov 25, 2024 · 1 comment
Labels
P2 Important issue. Windows

Comments

@cjhines
Copy link

cjhines commented Nov 25, 2024

Description of the issue

I have a bulk download function which is saving many files to DocumentDirectoryPath. After migrating from a different version of the library, I began getting an exception when I encounter the same file more than once (each file may appear more than once in the backend).

It seems to occur when CreateFileAsync is called on an existing file despite ReplaceExisting being specified.

This is the line which seemingly triggers the crash: https://github.com/birdofpreyru/react-native-fs/blob/master/windows/ReactNativeFs/ReactNativeModule.cpp#L939

Here is the terminal output:
Exception thrown at 0x00007FFDC192FA4C (KernelBase.dll) in app.exe: WinRT originate error - 0x80070020 : 'The file is in use. Please close the file before continuing.'.

Here's my code:

const download = async ({ token, ...rest }: FileDownloadOptions) => {
  const { promise } = FileSystem.downloadFile({
    progressDivider: 100,
    progressInterval: 5000,
    headers: {
      token,
    },
    ...rest,
  });
  return promise;
};

  try {
    const token = await verifyTokenSession(getState(), dispatch);
    const file = fileEntities[fileId];
    const downloadPath = `${FileSystem.DocumentDirectoryPath}/${fileName}`;
    const fromUrl = 'REDACTED';
    await download({
      fromUrl,
      toFile: downloadPath,
      token,
    });
    const dateDownloaded = new Date().toISOString();
    const updatedFile: File = { ...file, dateDownloaded };
    return updatedFile;
  } catch (error) {
    console.warn(error);
  }

Stack trace:

>	ReactNativeFs.dll!winrt::throw_hresult(const winrt::hresult result) Line 5089	C++
 	ReactNativeFs.dll!winrt::check_hresult(const winrt::hresult result) Line 5159	C++
 	ReactNativeFs.dll!winrt::impl::consume_Windows_Foundation_IAsyncOperation<winrt::Windows::Foundation::IAsyncOperation<winrt::Windows::Storage::StorageFile>,winrt::Windows::Storage::StorageFile>::GetResults() Line 116	C++
 	ReactNativeFs.dll!winrt::impl::await_adapter<winrt::Windows::Foundation::IAsyncOperation<winrt::Windows::Storage::StorageFile>>::await_resume() Line 3405	C++
 	ReactNativeFs.dll!winrt::ReactNativeFs::ReactNativeModule::ProcessDownloadRequestAsync$_ResumeCoro$1() Line 940	C++
 	ReactNativeFs.dll!std::experimental::coroutine_handle<void>::resume() Line 104	C++
 	ReactNativeFs.dll!winrt::impl::disconnect_aware_handler<winrt::impl::await_adapter<winrt::Windows::Foundation::IAsyncOperation<winrt::Windows::Storage::StorageFolder>>>::Complete() Line 3364	C++
 	ReactNativeFs.dll!winrt::impl::disconnect_aware_handler<winrt::impl::await_adapter<winrt::Windows::Foundation::IAsyncOperation<winrt::Windows::Storage::StorageFolder>>>::operator()<winrt::Windows::Foundation::IAsyncOperation<winrt::Windows::Storage::StorageFolder> const &>(const winrt::Windows::Foundation::IAsyncOperation<winrt::Windows::Storage::StorageFolder> & __formal, winrt::Windows::Foundation::AsyncStatus status) Line 3345	C++
 	ReactNativeFs.dll!winrt::impl::delegate<winrt::Windows::Foundation::AsyncOperationCompletedHandler<winrt::Windows::Storage::StorageFolder>,winrt::impl::disconnect_aware_handler<winrt::impl::await_adapter<winrt::Windows::Foundation::IAsyncOperation<winrt::Windows::Storage::StorageFolder>>>>::Invoke(void * asyncInfo, int asyncStatus) Line 839	C++
 	windows.storage.dll!00007ffdbf85dc91()	Unknown
 	windows.storage.dll!00007ffdbf85d94b()	Unknown
 	windows.storage.dll!00007ffdbf85d836()	Unknown
 	windows.storage.dll!00007ffdbf85d7a3()	Unknown
 	SHCore.dll!00007ffdc4228abc()	Unknown
 	SHCore.dll!00007ffdc42279b6()	Unknown
 	SHCore.dll!00007ffdc42277c1()	Unknown
 	kernel32.dll!00007ffdc412259d()	Unknown
 	ntdll.dll!00007ffdc44caf38()	Unknown

Specs

  • @dr.pogodin/react-native-fs: 2.28.1
  • react-native: 0.75.3
  • react-native-windows: 0.75.9
  • react-native-blob-util: 0.19.11
@cjhines cjhines changed the title xception thrown on Windows if a file alrady exists Exception thrown on Windows if file already exists Nov 25, 2024
@cjhines
Copy link
Author

cjhines commented Nov 25, 2024

What's interesting is that I also get a hresult_error when calling FileSystem.exists on a non-existing file:

co_await folder.GetItemAsync(fileName); leads to The system cannot find the file specified

@birdofpreyru birdofpreyru added P2 Important issue. Windows labels Nov 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 Important issue. Windows
Projects
None yet
Development

No branches or pull requests

2 participants