Repository: conan-io/conan-center-index

Issue:
[package] all: "Access is denied" in os.rename() on Windows
### Package and Environment Details (include every applicable attribute)
  * Package Name/Version: **almost all packages affected**
  * Operating System+version: **Windows 10**
  * Compiler+version: **MSVC 16**
  * Conan version: **conan 1.35.2**
  * Python version: **Python 3.8.7**


### Conan profile (output of `conan profile show default` or `conan profile show <profile>` if custom profile is in use)
```
[settings]
os_build=Windows
os=Windows
arch=x86_64
arch_build=x86_64
compiler=Visual Studio
compiler.version=16
compiler.runtime=MD
build_type=Release
```

### Steps to reproduce (Include if Applicable)

This is a known issue. Solution provided by https://github.com/conan-io/conan/pull/6774
However most recipes still use `os.rename()` and not `tools.rename()`. 

### Log
```
b2/4.2.0: Configuring sources in C:\Users\xxx\.conan\data\b2\4.2.0\_\_\source
ERROR: b2/4.2.0: Error in source() method, line 58
os.rename(extracted_dir, "source")
PermissionError: [WinError 5] Access is denied: 'build-4.2.0' -> 'source'
```



Discussion:
@klimkin Thank you for reporting, we can add it to Hooks and prevent future errors. 

Resolving patch:
diff --git a/recipes/zlib/1.2.11/conanfile.py b/recipes/zlib/1.2.11/conanfile.py
--- a/recipes/zlib/1.2.11/conanfile.py
+++ b/recipes/zlib/1.2.11/conanfile.py
@@ -44,8 +44,7 @@ def package_id(self):
         del self.info.options.minizip
 
     def source(self):
-        tools.get(**self.conan_data["sources"][self.version])
-        os.rename("{}-{}".format(self.name, self.version), self._source_subfolder)
+        tools.get(**self.conan_data["sources"][self.version], destination=self._source_subfolder, strip_root=True)
 
     def _patch_sources(self):
         for patch in self.conan_data["patches"][self.version]:
@@ -82,20 +81,20 @@ def _rename_libraries(self):
             suffix = "d" if self.settings.build_type == "Debug" else ""
 
             if self.options.shared:
-                if self.settings.compiler == "Visual Studio":
+                if self.settings.compiler == "Visual Studio" and suffix:
                     current_lib = os.path.join(lib_path, "zlib%s.lib" % suffix)
-                    os.rename(current_lib, os.path.join(lib_path, "zlib.lib"))
+                    tools.rename(current_lib, os.path.join(lib_path, "zlib.lib"))
             else:
                 if self.settings.compiler == "Visual Studio":
                     current_lib = os.path.join(lib_path, "zlibstatic%s.lib" % suffix)
-                    os.rename(current_lib, os.path.join(lib_path, "zlib.lib"))
+                    tools.rename(current_lib, os.path.join(lib_path, "zlib.lib"))
                 elif self.settings.compiler == "gcc":
                     if self.settings.os != "Windows" or not self.settings.os.subsystem:
                         current_lib = os.path.join(lib_path, "libzlibstatic.a")
-                        os.rename(current_lib, os.path.join(lib_path, "libzlib.a"))
+                        tools.rename(current_lib, os.path.join(lib_path, "libzlib.a"))
                 elif self.settings.compiler == "clang":
                     current_lib = os.path.join(lib_path, "zlibstatic.lib")
-                    os.rename(current_lib, os.path.join(lib_path, "zlib.lib"))
+                    tools.rename(current_lib, os.path.join(lib_path, "zlib.lib"))
 
     def _extract_license(self):
         with tools.chdir(os.path.join(self.source_folder, self._source_subfolder)):


Test patch: