From ddb75c06ca6517f784a7c7b6ceea0309d12dc00f Mon Sep 17 00:00:00 2001
From: Agate <me@agate.blue>
Date: Fri, 5 Jun 2020 06:09:46 +0200
Subject: [PATCH] Revert "Merge branch 'fix-import-python-3-5' into 'develop'"

This reverts merge request !1129
---
 .../music/management/commands/import_files.py | 31 +++++++------------
 changes/changelog.d/1147.bugfix               |  1 -
 2 files changed, 11 insertions(+), 21 deletions(-)
 delete mode 100644 changes/changelog.d/1147.bugfix

diff --git a/api/funkwhale_api/music/management/commands/import_files.py b/api/funkwhale_api/music/management/commands/import_files.py
index 73fda500a..fab980510 100644
--- a/api/funkwhale_api/music/management/commands/import_files.py
+++ b/api/funkwhale_api/music/management/commands/import_files.py
@@ -23,30 +23,21 @@ from funkwhale_api.common import utils as common_utils
 from funkwhale_api.music import models, tasks, utils
 
 
-def dir_scanner(scanner, extensions, recursive, ignored):
-    for entry in scanner:
-        if entry.is_file():
-            for e in extensions:
-                if entry.name.lower().endswith(".{}".format(e.lower())):
-                    if entry.path not in ignored:
-                        yield entry.path
-        elif recursive and entry.is_dir():
-            yield from dir_scanner(
-                entry, extensions, recursive=recursive, ignored=ignored
-            )
-
-
 def crawl_dir(dir, extensions, recursive=True, ignored=[]):
     if os.path.isfile(dir):
         yield dir
         return
-    else:
-        try:
-            scanner = os.scandir(dir)
-            yield from dir_scanner(scanner, extensions, recursive, ignored)
-        finally:
-            if hasattr(scanner, "close"):
-                scanner.close()
+    with os.scandir(dir) as scanner:
+        for entry in scanner:
+            if entry.is_file():
+                for e in extensions:
+                    if entry.name.lower().endswith(".{}".format(e.lower())):
+                        if entry.path not in ignored:
+                            yield entry.path
+            elif recursive and entry.is_dir():
+                yield from crawl_dir(
+                    entry, extensions, recursive=recursive, ignored=ignored
+                )
 
 
 def batch(iterable, n=1):
diff --git a/changes/changelog.d/1147.bugfix b/changes/changelog.d/1147.bugfix
deleted file mode 100644
index abdad21a7..000000000
--- a/changes/changelog.d/1147.bugfix
+++ /dev/null
@@ -1 +0,0 @@
-Fixed an issue where in-place importing didn't work for directories on machines running Python 3.5 (#1148, #1147)
\ No newline at end of file
-- 
GitLab