Repository: opendatacube/datacube-core

Issue:
Dataset path incorrect for mapped network drive (Windows)
### Expected behaviour

Being able to load data with `dc.load('product_name')`.

### Actual behaviour

Rasterio cannot find the file, as it is only given the path and not the host. Eg. for a file \\\\host\path\to\file, only \path\to\file is given. 

This is caused by:
https://github.com/opendatacube/datacube-core/blob/596043d66d54744fd4d56eb72f385bb77d5c7017/datacube/utils/__init__.py#L659
which ignores `components.netloc`

### Steps to reproduce the behaviour

- Index a dataset from a mapped network drive - `datacube dataset add dataset_name`
- Try to load data using `dc.load('product_name')

### Environment information

* Which ``datacube --version`` are you using?
Open Data Cube core, version 1.6.1+146.g10adc9ff
* What datacube deployment/environment are you running against?
Windows 10/ Python 3.7, local datacube with networked postgres server.

### Notes

The drive is mapped to `p:`, and all commands are executed from an Anaconda environment with the current directory on the mapped drive. I imagine similar behaviour would occur if the path given was a network path (eg. `datacube dataset add \\host\path\to\file`) but have not checked this out.
In the `dataset_location` table in the postgres database, the locations are listed fully (`//host/path/to/file`).

### Workaround

I've added the netloc:
```
    path = components.path if components.netloc == '' else '//{}{}'.format(components.netloc, components.path)
    path = url2pathname(path)
```
This is probably not very robust though. 

Dataset path incorrect for mapped network drive (Windows)
### Expected behaviour

Being able to load data with `dc.load('product_name')`.

### Actual behaviour

Rasterio cannot find the file, as it is only given the path and not the host. Eg. for a file \\\\host\path\to\file, only \path\to\file is given. 

This is caused by:
https://github.com/opendatacube/datacube-core/blob/596043d66d54744fd4d56eb72f385bb77d5c7017/datacube/utils/__init__.py#L659
which ignores `components.netloc`

### Steps to reproduce the behaviour

- Index a dataset from a mapped network drive - `datacube dataset add dataset_name`
- Try to load data using `dc.load('product_name')

### Environment information

* Which ``datacube --version`` are you using?
Open Data Cube core, version 1.6.1+146.g10adc9ff
* What datacube deployment/environment are you running against?
Windows 10/ Python 3.7, local datacube with networked postgres server.

### Notes

The drive is mapped to `p:`, and all commands are executed from an Anaconda environment with the current directory on the mapped drive. I imagine similar behaviour would occur if the path given was a network path (eg. `datacube dataset add \\host\path\to\file`) but have not checked this out.
In the `dataset_location` table in the postgres database, the locations are listed fully (`//host/path/to/file`).

### Workaround

I've added the netloc:
```
    path = components.path if components.netloc == '' else '//{}{}'.format(components.netloc, components.path)
    path = url2pathname(path)
```
This is probably not very robust though. 



Discussion:

Resolving patch:
diff --git a/datacube/utils/__init__.py b/datacube/utils/__init__.py
--- a/datacube/utils/__init__.py
+++ b/datacube/utils/__init__.py
@@ -658,6 +658,12 @@ def uri_to_local_path(local_uri):
 
     path = url2pathname(components.path)
 
+    if components.netloc:
+        if os.name == 'nt':
+            path = '//{}{}'.format(components.netloc, path)
+        else:
+            raise ValueError('Only know how to use `netloc` urls on Windows')
+
     return pathlib.Path(path)
 
 


Test patch:
diff --git a/tests/test_utils.py b/tests/test_utils.py
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -80,10 +80,14 @@ def test_stats_dates():
 def test_uri_to_local_path():
     if os.name == 'nt':
         assert 'C:\\tmp\\test.tmp' == str(uri_to_local_path('file:///C:/tmp/test.tmp'))
+        assert '\\\\remote\\path\\file.txt' == str(uri_to_local_path('file://remote/path/file.txt'))
 
     else:
         assert '/tmp/something.txt' == str(uri_to_local_path('file:///tmp/something.txt'))
 
+        with pytest.raises(ValueError):
+            uri_to_local_path('file://remote/path/file.txt')
+
     assert uri_to_local_path(None) is None
 
     with pytest.raises(ValueError):