After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 694466 - JHBuild deletes the whole checkout root if being passed a module with trailing slashes
JHBuild deletes the whole checkout root if being passed a module with trailin...
Status: RESOLVED FIXED
Product: jhbuild
Classification: Infrastructure
Component: general
unspecified
Other Linux
: Normal major
: ---
Assigned To: Jhbuild maintainers
Jhbuild QA
Depends on:
Blocks:
 
 
Reported: 2013-02-22 17:59 UTC by Emanuele Aina
Modified: 2013-07-10 14:27 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Fix handling of trailing slashes on command-line modules names (3.09 KB, patch)
2013-02-22 18:10 UTC, Emanuele Aina
none Details | Review
Fix handling of trailing slashes on command-line modules names (4.27 KB, patch)
2013-05-20 16:31 UTC, Emanuele Aina
committed Details | Review
Fix handling of trailing slashes on command-line modules names (4.27 KB, patch)
2013-07-10 14:27 UTC, Emanuele Aina
committed Details | Review

Description Emanuele Aina 2013-02-22 17:59:41 UTC
I was trying to build the 'gnome-desktop' module and being in the checkoutroot I hit TAB to complete the module name.

This resulted in the followind command being run (note the trailing slash :
 $ jhbuild buildone gnome-desktop/

Unfortunately Branch.get_module_basename() calls os.path.basename(self.module) and with a trailing slash it returns and empty string that will be joined in Branch.get_checkoutdir() to the checkoutroot.

This caused JHBuild to search for .git directory in the checkoutroot, and after failing it prompted me with the usual recovery options. Since I assumed my repo was broken for whatever reason, I choose "wipe and start over": due to the bug above JHBuild promptly deleted all my checkoutroot. :(
Comment 1 Emanuele Aina 2013-02-22 18:10:35 UTC
Created attachment 237204 [details] [review]
Fix handling of trailing slashes on command-line modules names

It is currently possible to delete the whole checkoutroot by adding
a trailing slash to a module name passed on the command line:

• Run `jhbuild buildone gnome-desktop/`
• Watch jhbuild error out as it is unable to find the repo
• Select 'Wipe directory and start over' (just kidding, *don't*
  select it!)
• Watch jhbuild delete your whole checkout root.

This happens because the module name is passed to os.path.basename()
which will return an empty string on trailing slashes.

JHBuild will then try to operate on the base checkout root, failing to
find any proper repo and promptly deleting all its content if told to
do so.

This patch does two things to prevent this error to occur:

• Strip all the trailing slashes from module names in
  Branch.get_module_basename()
• Refuse to accept an empty string for the module basename in
  Branch.get_checkoutdir()
Comment 2 Emanuele Aina 2013-05-20 15:40:26 UTC
If noone complains about it, I'd like to push the patch in a week.
Comment 3 Emanuele Aina 2013-05-20 16:31:45 UTC
Created attachment 244834 [details] [review]
Fix handling of trailing slashes on command-line modules names

Fixed trailing slashes handling in a couple of other places.
Comment 4 Colin Walters 2013-07-10 11:45:00 UTC
Review of attachment 244834 [details] [review]:

One minor comment.  Feel free to push after addressing.

::: jhbuild/moduleset.py
@@ +72,2 @@
     def get_module(self, module_name, ignore_case = False):
+        module_name = module_name.rstrip('/')

You use a literal '/' here...

::: jhbuild/versioncontrol/__init__.py
@@ +99,3 @@
     def get_module_basename(self):
+        # prevent basename() from returning empty strings on trailing '/'
+        module = self.module.rstrip(os.sep)

...and os.sep here.  The latter is better, so pick that consistently?
Comment 5 Emanuele Aina 2013-07-10 14:27:03 UTC
Changed to use os.sep everywhere. Thanks!

The following fix has been pushed:
2d12b3a Fix handling of trailing slashes on command-line modules names
Comment 6 Emanuele Aina 2013-07-10 14:27:12 UTC
Created attachment 248837 [details] [review]
Fix handling of trailing slashes on command-line modules names

It is currently possible to delete the whole checkoutroot by adding
a trailing slash to a module name passed on the command line:

• Run `jhbuild buildone gnome-desktop/`
• Watch jhbuild error out as it is unable to find the repo
• Select 'Wipe directory and start over' (just kidding, *don't*
  select it!)
• Watch jhbuild delete your whole checkout root.

This happens because the module name is passed to os.path.basename()
which will return an empty string on trailing slashes.

JHBuild will then try to operate on the base checkout root, failing to
find any proper repo and promptly deleting all its content if told to
do so.

This patch does two things to prevent this error to occur:

• Strip all the trailing slashes from module names in
  Branch.get_module_basename()
• Refuse to accept an empty string for the module basename in
  Branch.get_checkoutdir()

It also tries to strip trailing slashes from module names in a couple of
other places, trying to keep stuff working even when being passed one.