Skip to content

Replace create_temp_directory with the new create_temporary_directory#198

Merged
ahcorde merged 4 commits intoros2:rollingfrom
MichaelOrlov:morlov/add-create_temporary_directory
Jul 22, 2024
Merged

Replace create_temp_directory with the new create_temporary_directory#198
ahcorde merged 4 commits intoros2:rollingfrom
MichaelOrlov:morlov/add-create_temporary_directory

Conversation

@MichaelOrlov
Copy link
Copy Markdown
Contributor

@MichaelOrlov MichaelOrlov commented Jul 11, 2024

- The newly added `create_temporary_directory(..)` uses
std::filesystem::path and doesn't have platform-specific code.
- Also deprecated `create_temp_directory(..)` and `temp_directory_path`

Signed-off-by: Michael Orlov <michael.orlov@apex.ai>
@MichaelOrlov MichaelOrlov marked this pull request as ready for review July 11, 2024 20:41
@MichaelOrlov
Copy link
Copy Markdown
Contributor Author

cc: @ahcorde, @clalancette - ready for review.

Copy link
Copy Markdown
Contributor

@clalancette clalancette left a comment

Choose a reason for hiding this comment

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

Overall, looks good. I've left two things inline to fix.

This will also have to be paired with PRs to rcl_logging and rosbag2 so that they use the non-deprecated API.

- Throw std::invalid_argument exception if base_path argument contains
directory-separator.
- Add missing `#include <stdexcept>`

Signed-off-by: Michael Orlov <michael.orlov@apex.ai>
@MichaelOrlov
Copy link
Copy Markdown
Contributor Author

@clalancette, I addressed your comments.

Copy link
Copy Markdown
Contributor

@ahcorde ahcorde 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 small nit, otherwise LGTM

Comment on lines +349 to +351
auto it =
std::find(base_name.begin(), base_name.end(), std::filesystem::path::preferred_separator);
if (it != base_name.end()) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we can make this simpler by using the string.find method:

Suggested change
auto it =
std::find(base_name.begin(), base_name.end(), std::filesystem::path::preferred_separator);
if (it != base_name.end()) {
if (base_name.find(std::filesystem::path::preferred_separator) != base_name.npos) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in the 8b4087d commit

}
// mersenne twister random generator engine seeded with the std::random_device
std::mt19937 random_generator(std::random_device{}());
std::uniform_int_distribution<> distribution(0, 999999);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this interval is too small, now that I look at it. When I ran some tests locally, I always got 0 as the first digit. And that makes sense, because 999999 == F423F hex, so there will never be something in the first digit. For 6 digits of hex, we should make this 0xFFFFFF:

Suggested change
std::uniform_int_distribution<> distribution(0, 999999);
std::uniform_int_distribution<> distribution(0, 0xFFFFFF);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@clalancette Good catch! I forgot that we convert in HEX and that in hex the range should be bigger.
Fixed in the 8b4087d commit.

- Replace std::find with string::find
- Use bigger upper limit 0xFFFFFF for the uniform distribution.

Signed-off-by: Michael Orlov <michael.orlov@apex.ai>
@MichaelOrlov
Copy link
Copy Markdown
Contributor Author

Pulls: #198
Gist: https://gist.githubusercontent.com/MichaelOrlov/053726535ccac0098e0f98cd4d8aa796/raw/b89be092beb15684cb63ffbb1ffd8f9203be2c36/ros2.repos
BUILD args: --packages-above-and-dependencies rcpputils
TEST args: --packages-above rcpputils
ROS Distro: rolling
Job: ci_launcher
ci_launcher ran: https://ci.ros2.org/job/ci_launcher/14241

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Linux-rhel Build Status
  • Windows Build Status

- Use fs::path::generic_string() instead of the c_str() for
rcpputils::fs::path construction.

Signed-off-by: Michael Orlov <michael.orlov@apex.ai>
@MichaelOrlov MichaelOrlov force-pushed the morlov/add-create_temporary_directory branch from 0ea95b0 to fb089c8 Compare July 18, 2024 07:05
@MichaelOrlov
Copy link
Copy Markdown
Contributor Author

Re-run Windows CI after addressing build failures

  • Windows Build Status

Copy link
Copy Markdown
Collaborator

@fujitatomoya fujitatomoya left a comment

Choose a reason for hiding this comment

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

lgtm with green CI

@ahcorde
Copy link
Copy Markdown
Contributor

ahcorde commented Jul 19, 2024

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Linux-rhel Build Status
  • Windows Build Status

Included ros2/rosbag2#1740 and ros2/rcl_logging#117

@ahcorde ahcorde merged commit acd78ce into ros2:rolling Jul 22, 2024
@MichaelOrlov MichaelOrlov deleted the morlov/add-create_temporary_directory branch July 22, 2024 23:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants