Skip to content

[Windows] Exception thrown if file already exists #89

Description

@cjhines

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    On HoldBlocked for some reason.P2Important issue.Windows

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions