-
Notifications
You must be signed in to change notification settings - Fork 1
Refactor dehydrate file #193
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
Merged
Merged
Changes from all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
21bd1ad
Create napi safe wrap
dajimenezriv-internxt 819a1f1
Extract create folder placeholder
dajimenezriv-internxt cc1b678
Extract create file placeholder
dajimenezriv-internxt 444a2d5
Extract get file identity
dajimenezriv-internxt b5eff5e
Update package.json
dajimenezriv-internxt fe31746
Extract connect sync root
dajimenezriv-internxt 32c5ea9
Extract hydrate file
dajimenezriv-internxt 75681d6
Hydrate file thread safe
dajimenezriv-internxt 205f2be
Improve safe wrap
dajimenezriv-internxt 9648c94
Remove delete file from c++
dajimenezriv-internxt 46ee84c
Extract convert to placeholder
dajimenezriv-internxt 313dfbf
Refactor register sync root
dajimenezriv-internxt ff28084
Extract code
dajimenezriv-internxt d1a7164
Improve
dajimenezriv-internxt 70d004e
Simplify providerId
dajimenezriv-internxt 69ce991
Commit
dajimenezriv-internxt 1020526
Commit
dajimenezriv-internxt e94646e
Commit
dajimenezriv-internxt 0601df9
Update get_registered_sync_roots.cpp
dajimenezriv-internxt 73a1c9e
Update addon.node
dajimenezriv-internxt ae38d77
Commt
dajimenezriv-internxt f7b6a44
Commit
dajimenezriv-internxt 41028a0
Simplify unregister
dajimenezriv-internxt 38a0e29
Fix wrapper
dajimenezriv-internxt 4832626
Remove context
dajimenezriv-internxt d947054
Improve napi
dajimenezriv-internxt 9d096c0
Template napi_extract_args
dajimenezriv-internxt 249d71c
Extract dehydrate file wrapper
dajimenezriv-internxt 2d39fb1
Refactor dehydrate file
dajimenezriv-internxt 0a6216f
Throw exceptions
dajimenezriv-internxt 4577789
Commit
dajimenezriv-internxt 2a9867b
Merge branch 'master' into refactor-dehydrate-file
dajimenezriv-internxt 4388e5c
Update hydrate_file.cpp
dajimenezriv-internxt da16704
Update hydrate_file.cpp
dajimenezriv-internxt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| #pragma once | ||
|
|
||
| #include <node_api.h> | ||
|
|
||
| napi_value dehydrate_file(napi_env env, napi_callback_info info); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| #include <windows.h> | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Code is nearly the same.
I've tested these three possible errors and all work perfectly. |
||
| #include "napi_extract_args.h" | ||
| #include "stdafx.h" | ||
|
|
||
| napi_value dehydrate_file(napi_env env, napi_callback_info info) { | ||
| auto [rawPath] = napi_extract_args<1>(env, info); | ||
| const wchar_t* path = rawPath.c_str(); | ||
|
|
||
| DWORD attrib = GetFileAttributesW(path); | ||
|
|
||
| if (attrib & FILE_ATTRIBUTE_DIRECTORY) { | ||
| throw std::runtime_error("Cannot dehydrate folder"); | ||
| } | ||
|
|
||
| winrt::handle placeholder(CreateFileW(path, 0, FILE_READ_DATA, nullptr, OPEN_EXISTING, 0, nullptr)); | ||
|
|
||
| LARGE_INTEGER offset; | ||
| offset.QuadPart = 0; | ||
| LARGE_INTEGER length; | ||
| GetFileSizeEx(placeholder.get(), &length); | ||
|
|
||
| HRESULT hr = CfDehydratePlaceholder(placeholder.get(), offset, length, CF_DEHYDRATE_FLAG_NONE, NULL); | ||
|
|
||
| if (SUCCEEDED(hr)) { | ||
| return nullptr; | ||
| } | ||
|
|
||
| DWORD err = HRESULT_CODE(hr); | ||
|
|
||
| if (err == ERROR_SHARING_VIOLATION || err == ERROR_CLOUD_FILE_IN_USE) { | ||
| MessageBoxW( | ||
| nullptr, | ||
| L"Unable to free up space because the file is currently in use.\nPlease close the file and try again.", | ||
| L"File in use", | ||
| MB_OK | MB_ICONWARNING | MB_SYSTEMMODAL); | ||
| } | ||
|
|
||
| winrt::throw_hresult(hr); | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We neo longer need to check this manually, the error given by CfDehydratePlaceholder is better as explained below.