src/eric7/RemoteServer/EricServerFileSystemRequestHandler.py

branch
server
changeset 10630
552a790fd9bc
parent 10610
bb0149571d94
child 10633
dda7e43934dc
--- a/src/eric7/RemoteServer/EricServerFileSystemRequestHandler.py	Tue Feb 27 15:05:53 2024 +0100
+++ b/src/eric7/RemoteServer/EricServerFileSystemRequestHandler.py	Fri Mar 08 15:30:23 2024 +0100
@@ -140,23 +140,7 @@
             directory = os.getcwd()
 
         try:
-            listing = []
-            for dirEntry in os.scandir(directory):
-                filestat = dirEntry.stat()
-                entry = {
-                    "name": dirEntry.name,
-                    "path": dirEntry.path,
-                    "is_dir": dirEntry.is_dir(),
-                    "is_file": dirEntry.is_file(),
-                    "is_link": dirEntry.is_symlink(),
-                    "mode": filestat.st_mode,
-                    "mode_str": stat.filemode(filestat.st_mode),
-                    "size": filestat.st_size,
-                    "mtime": time.strftime(
-                        "%Y-%m-%d %H:%M:%S", time.localtime(filestat.st_mtime)
-                    ),
-                }
-                listing.append(entry)
+            listing = self.__scanDirectory(directory, params["recursive"])
 
             return {
                 "ok": True,
@@ -170,6 +154,43 @@
                 "error": str(err),
             }
 
+    def __scanDirectory(self, directory, recursive, withHidden=False):
+        """
+        Private method to scan a given directory.
+
+        @param directory path of the directory to be scanned
+        @type str
+        @param recursive flag indicating a recursive scan
+        @type bool
+        @param withHidden flag indicating to list hidden files and directories
+            as well (defaults to False)
+        @type bool (optional)
+        """
+        listing = []
+        for dirEntry in os.scandir(directory):
+            filestat = dirEntry.stat()
+            if withHidden or not dirEntry.name.startswith("."):
+                entry = {
+                    "name": dirEntry.name,
+                    "path": dirEntry.path,
+                    "is_dir": dirEntry.is_dir(),
+                    "is_file": dirEntry.is_file(),
+                    "is_link": dirEntry.is_symlink(),
+                    "mode": filestat.st_mode,
+                    "mode_str": stat.filemode(filestat.st_mode),
+                    "size": filestat.st_size,
+                    "mtime": filestat.st_mtime,
+                    "mtime_str": time.strftime(
+                        "%Y-%m-%d %H:%M:%S", time.localtime(filestat.st_mtime)
+                    ),
+                }
+                listing.append(entry)
+                
+                if entry["is_dir"] and recursive:
+                    listing += self.__scanDirectory(dirEntry.path, recursive)
+
+        return listing
+
     def __stat(self, params):
         """
         Private method to get the status of a file.
@@ -327,8 +348,9 @@
             with open(filename, "wb"):
                 pass
 
+        newline = None if params["newline"] == "<<none>>" else params["newline"]
         try:
-            with open(filename, "rb") as f:
+            with open(filename, "rb", newline=newline) as f:
                 data = f.read()
             return {
                 "ok": True,
@@ -369,8 +391,9 @@
                 os.rename(filename, backupFilename)
 
         # 2. write the data to the file and reset the permissions
+        newline = None if params["newline"] == "<<none>>" else params["newline"]
         try:
-            with open(filename, "wb") as f:
+            with open(filename, "wb", newline=newline) as f:
                 f.write(data)
             if params["with_backup"] and perms_valid:
                 os.chmod(filename, permissions)

eric ide

mercurial