diff --git a/bob/devtools/build.py b/bob/devtools/build.py
index 5f3b673ccb75b7d8e434cfa04105ced17e438963..2486af226fe625a20bcefc4c33189cdc87d5bb26 100644
--- a/bob/devtools/build.py
+++ b/bob/devtools/build.py
@@ -65,8 +65,8 @@ def should_skip_build(metadata_tuples):
 def next_build_number(channel_url, basename):
     """Calculates the next build number of a package given the channel.
 
-    This function returns the next build number (integer) for a package given its
-    resulting tarball base filename (can be obtained with
+    This function returns the next build number (integer) for a package given
+    its resulting tarball base filename (can be obtained with
     :py:func:`get_output_path`).
 
 
@@ -212,7 +212,8 @@ def get_parsed_recipe(metadata):
 def exists_on_channel(channel_url, basename):
     """Checks on the given channel if a package with the specs exist.
 
-    This procedure always ignores the package hash code, if one is set
+    This procedure always ignores the package hash code, if one is set.  It
+    differentiates between `.conda` and `.tar.bz2` packages.
 
     Args:
 
@@ -230,10 +231,10 @@ def exists_on_channel(channel_url, basename):
 
         # remove .tar.bz2/.conda from name, then split from the end twice, on
         # '-'
-        if name.endswith('.tar.bz2'):
-            name, version, build = name[:-8].rsplit("-", 2)
-        elif name.endswith('.conda'):
+        if name.endswith('.conda'):
             name, version, build = name[:-6].rsplit("-", 2)
+        elif name.endswith('.tar.bz2'):
+            name, version, build = name[:-8].rsplit("-", 2)
         else:
             raise RuntimeError("Package name %s does not end in either " \
                     ".tar.bz2 or .conda" % (name,))
@@ -252,9 +253,10 @@ def exists_on_channel(channel_url, basename):
     other_build_numbers = [_get_build_number(os.path.basename(k)) for k in urls]
 
     if self_build_number in other_build_numbers:
-        return "".join(
-            (channel_url, urls[other_build_numbers.index(self_build_number)])
-        )
+        candidate = urls[other_build_numbers.index(self_build_number)]
+        pkg_type = '.conda' if basename.endswidth('.conda') else '.tar.bz2'
+        if candidate.endswith(pkg_type):  #match
+            return "".join(channel_url, candidate)
 
 
 def remove_pins(deps):