loader: reorder some code in `get_mgroup`
[nit.git] / src / loader.nit
index bc268fa..7ff71a6 100644 (file)
@@ -396,10 +396,15 @@ redef class ModelBuilder
        # Note: `paths` is also used to look for mgroups
        fun get_mgroup(dirpath: String): nullable MGroup
        do
-               if not dirpath.file_exists then do
+               var stat = dirpath.file_stat
+
+               if stat == null then do
+                       # search dirless directories in known -I paths
+                       if dirpath.chars.has('/') then return null
                        for p in paths do
                                var try = p / dirpath
-                               if try.file_exists then
+                               stat = try.file_stat
+                               if stat != null then
                                        dirpath = try
                                        break label
                                end
@@ -407,20 +412,19 @@ redef class ModelBuilder
                        return null
                end label
 
+               # Filter out non-directories
+               if not stat.is_dir then
+                       return null
+               end
+
+               # Fast track, the path is already known
                var rdp = module_absolute_path(dirpath)
                if mgroups.has_key(rdp) then
                        return mgroups[rdp]
                end
 
-               # Filter out non-directories
-               var stat = dirpath.file_stat
-               if stat == null or not stat.is_dir then
-                       mgroups[rdp] = null
-                       return null
-               end
-
                # By default, the name of the package or group is the base_name of the directory
-               var pn = rdp.basename(".nit")
+               var pn = rdp.basename
 
                # Check `package.ini` that indicate a package
                var ini = null