Repository: conan-io/conan

Issue:
Bug: conan config install
To help us debug your issue please explain:

- [x] I've read the [CONTRIBUTING guide](https://github.com/conan-io/conan/blob/develop/.github/CONTRIBUTING.md).
- [x] I've specified the Conan version, operating system version and any tool that can be relevant.
- [x] I've explained the steps to reproduce the error or the motivation/use case of the question/suggestion.

Following situation:
Running conan 1.15.1 on Linux (Ubuntu 18.4 LTS)
When loading our configuration to a new `CONAN_USER_HOME` and start import our configuration:
`conan config install ~/work/scripts/conan/config/`
I get the following error:
`ERROR: [Errno 2] No such file or directory: '/home/j/tempconan/.conan/remotes.json'`

When I just open in between `conan remote list` it works afterwards.

When running with Conan 1.14.1 it also works. So it must be a bug afterwards.

Here the recipe:
```
mkdir tempconan && cd tempconan
export CONAN_USER_HOME=/home/j/tempconan
conan config install ~/work/scripts/conan/config/
```

And the callstack:
```
j@ubuntu:~/tempconan$ conan config install ~/work/scripts/conan/config/Copying file version.txt to /home/j/tempconan/.conan/.
Copying file artifacts.properties to /home/j/tempconan/.conan/.
Processing conan.conf
Traceback (most recent call last):
  File "/home/j/.local/lib/python3.6/site-packages/conans/client/command.py", line 1607, in run
    method(args[0][1:])
  File "/home/j/.local/lib/python3.6/site-packages/conans/client/command.py", line 478, in config
    target_folder=args.target_folder)
  File "/home/j/.local/lib/python3.6/site-packages/conans/client/conan_api.py", line 92, in wrapper
    return f(*args, **kwargs)
  File "/home/j/.local/lib/python3.6/site-packages/conans/client/conan_api.py", line 621, in config_install
    source_folder=source_folder, target_folder=target_folder)
  File "/home/j/.local/lib/python3.6/site-packages/conans/client/conf/config_installer.py", line 230, in configuration_install
    _process_config(config, cache, output, requester)
  File "/home/j/.local/lib/python3.6/site-packages/conans/client/conf/config_installer.py", line 182, in _process_config
    _process_folder(config, config.uri, cache, output)
  File "/home/j/.local/lib/python3.6/site-packages/conans/client/conf/config_installer.py", line 93, in _process_folder
    os.remove(cache.registry_path)
FileNotFoundError: [Errno 2] No such file or directory: '/home/j/tempconan/.conan/remotes.json'

ERROR: [Errno 2] No such file or directory: '/home/j/tempconan/.conan/remotes.json'

```





Discussion:
Checked just again the version, where it happens:
1.14.5 OK
1.15.0 Failure

Looks like this place:

```python
elif f in ("registry.txt", "registry.json"):
                os.remove(cache.registry_path) <----- Should be try: ... except FileNotFoundError: pass
                shutil.copy(os.path.join(root, f), cache.conan_folder)
                migrate_registry_file(cache, output)
```
Thanks for reporting, let's try to fix it for next release.

Resolving patch:
diff --git a/conans/client/conf/config_installer.py b/conans/client/conf/config_installer.py
--- a/conans/client/conf/config_installer.py
+++ b/conans/client/conf/config_installer.py
@@ -90,9 +90,13 @@ def _process_folder(config, folder, cache, output):
                 output.info("Defining remotes from remotes.txt")
                 _handle_remotes(cache, os.path.join(root, f))
             elif f in ("registry.txt", "registry.json"):
-                os.remove(cache.registry_path)
-                shutil.copy(os.path.join(root, f), cache.cache_folder)
-                migrate_registry_file(cache, output)
+                try:
+                    os.remove(cache.registry_path)
+                except OSError:
+                    pass
+                finally:
+                    shutil.copy(os.path.join(root, f), cache.cache_folder)
+                    migrate_registry_file(cache, output)
             elif f == "remotes.json":
                 # Fix for Conan 2.0
                 raise ConanException("remotes.json install is not supported yet. Use 'remotes.txt'")


Test patch:
diff --git a/conans/test/unittests/client/conf/config_installer/__init__.py b/conans/test/unittests/client/conf/config_installer/__init__.py
new file mode 100644
diff --git a/conans/test/unittests/client/conf/config_installer/test_process_folder.py b/conans/test/unittests/client/conf/config_installer/test_process_folder.py
new file mode 100644
--- /dev/null
+++ b/conans/test/unittests/client/conf/config_installer/test_process_folder.py
@@ -0,0 +1,29 @@
+# coding=utf-8
+
+import os
+import unittest
+from collections import namedtuple
+
+import mock
+
+from conans.client.conf.config_installer import _process_folder
+from conans.test.utils.test_files import temp_folder
+from conans.test.utils.tools import TestBufferConanOutput, save_files
+
+
+class ProcessFolderTests(unittest.TestCase):
+    def test_config_in_empty_folder(self):
+        output = TestBufferConanOutput()
+        cache_t = namedtuple("_", ["cache_folder", "registry_path"])
+        config_t = namedtuple("_", ["source_folder"])
+
+        cache_folder = temp_folder()
+        remotes_json = os.path.join(cache_folder, "registry.json")
+        cache = cache_t(cache_folder=cache_folder, registry_path=remotes_json)
+        ori_folder = temp_folder()
+        save_files(ori_folder, {'registry.json': 'whatever'})
+        with mock.patch("conans.client.conf.config_installer.migrate_registry_file",
+                        return_value=None):
+            self.assertFalse(os.path.exists(remotes_json))
+            _process_folder(config_t(None), ori_folder, cache, output)
+        self.assertTrue(os.path.exists(remotes_json))