Skip to content

Use Windows-specific renaming function #90

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 3 commits into from
Apr 15, 2019

Conversation

dgreen-arm
Copy link
Contributor

On Windows, rename() fails if the new filename already exists.
Use the Windows specific function MoveFileExA with the
MOVEFILE_REPLACE_EXISTING flag set instead to do renames.

On Windows, rename() fails if the new filename already exists.
Use the Windows specific function MoveFileExA with the
MOVEFILE_REPLACE_EXISTING flag set instead to do renames.
@@ -209,7 +213,12 @@ psa_status_t psa_its_set( psa_storage_uid_t uid,
}
if( status == PSA_SUCCESS )
{
#if defined(_WIN32)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please avoid non-structural use of the preprocessor, with #ifdef around things that aren't a standalone C block. Here, I think the best solution would be to define a function-like macro rename_replace_existing( oldpath, newpath ) with a platform-dependent definition.

@gilles-peskine-arm gilles-peskine-arm added bug Something isn't working needs: work The pull request needs rework before it can be merged. labels Apr 10, 2019
Copy link
Collaborator

@gilles-peskine-arm gilles-peskine-arm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a little documentation improvement please.

@@ -58,6 +62,13 @@
#define PSA_ITS_MAGIC_STRING "PSA\0ITS\0"
#define PSA_ITS_MAGIC_LENGTH 8

#if defined(_WIN32)
#define rename_replace_existing( oldpath, newpath ) \
(!MoveFileExA( oldpath, newpath, MOVEFILE_REPLACE_EXISTING ))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style:

Suggested change
(!MoveFileExA( oldpath, newpath, MOVEFILE_REPLACE_EXISTING ))
( ! MoveFileExA( oldpath, newpath, MOVEFILE_REPLACE_EXISTING ) )

@gilles-peskine-arm gilles-peskine-arm added needs: review The pull request is ready for review. This generally means that it has no known issues. and removed needs: work The pull request needs rework before it can be merged. labels Apr 11, 2019
@k-stachowiak k-stachowiak self-requested a review April 12, 2019 09:04
@Patater Patater removed the needs: review The pull request is ready for review. This generally means that it has no known issues. label Apr 15, 2019
@Patater Patater merged commit 125a1e9 into ARMmbed:development Apr 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants