Rex icon indicating copy to clipboard operation
Rex copied to clipboard

extract function try to create the root directory

Open zhumengu opened this issue 4 years ago • 1 comments

Describe the bug

When extracting to the root directory, try to create the root directory, uninitialized value

Use of uninitialized value $splitted_dir[0] in string eq at /home/user/perl5/lib/perl5/Rex/Commands/Fs.pm line 341 

How to reproduce it

Steps to reproduce the behavior:

  1. extract "/tmp/mypackage.tar.gz", to => "/";

Shortest code example that demonstrates the bug:

extract /tmp/mypackage.tar.gz, to => "/";

https://github.com/RexOps/Rex/blob/df033cee5be8011207df9f5269bb25d74b94550f/lib/Rex/Commands/Fs.pm#L339 When $dir is "/", @splitted_dir is empty; https://github.com/RexOps/Rex/blob/df033cee5be8011207df9f5269bb25d74b94550f/lib/Rex/Commands/Fs.pm#L341

Expected behavior

no warning

Circumstances

  • Rex version: (R)?ex 1.13.1
  • Perl version: perl 5, version 32, subversion 1 (v5.32.1) built for x86_64-linux-thread-multi
  • OS running rex: Manjaro Linux \r (\n) (\l)
  • OS managed by rex:
  • How rex was installed: cpanm

Debug log

zhumengu avatar May 18 '21 04:05 zhumengu

Thanks for the report, @zhumengu, good catch!

ferki avatar Jul 08 '21 22:07 ferki

Hi @zhumengu, thanks for your patience, and coming back to this issue!

I don't consider it as "not planned", so I am reopening. Let's give it a chance to be fixed in the future by any volunteers who have enough capacity to donate.

ferki avatar Jan 30 '23 15:01 ferki

Thanks again for reporting and for your patience, @zhumengu!

The solution for this turned out to be more complicated then originally expected. After doing several other refactoring steps, it became relatively straightforward to:

  • add tests for mkdir(), including making sure it doesn't emit any warnings
  • offload all the directory name manipulation logic to the File::Spec variant relevant for the platform that is being managed by Rex (via Rex::Helper::File::Spec)

The fix is merged now, and will be part of the next release.

ps.: Since extract to the root directory itself was working (given sufficient permissions to do so), and the problem was about emitting warnings when trying to call mkdir on the root directory, I might update the title of the issue to better reflect that in future searches.

ferki avatar Feb 26 '23 21:02 ferki