Skip to content

Commit

Permalink
Merge PR #320 into 16.0
Browse files Browse the repository at this point in the history
Signed-off-by lmignon
  • Loading branch information
OCA-git-bot committed Feb 6, 2024
2 parents 968d919 + 46aab5b commit f3b8084
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 5 deletions.
4 changes: 2 additions & 2 deletions fs_storage/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Filesystem Storage Backend
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:f7f1c906045d3f8e370a9b1a9d952f9df4dc14ed1a3003b4370f1807993a64cd
!! source digest: sha256:d76c1c7778c0c2f02c33b8d9852971df449268a7e5941c6d82483d99486b91e4
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand Down Expand Up @@ -117,7 +117,7 @@ When you create a new backend, you must specify the following:
* The protocol options. These are the options that will be passed to the
fsspec python package when creating the filesystem. These options depend
on the protocol used and are described in the fsspec documentation.
* Resolve env vars. This options resolves the protocol options values starting
* Resolve env vars. This options resolves the protocol options values starting
with $ from environment variables

Some protocols defined in the fsspec package are wrappers around other
Expand Down
23 changes: 22 additions & 1 deletion fs_storage/models/fs_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,12 +266,33 @@ def _compute_options_properties(self) -> None:
doc = inspect.getdoc(cls.__init__)
rec.options_properties = f"__init__{signature}\n{doc}"

def _get_marker_file_name(self):
return ".odoo_fs_storage_%s.marker" % self.id

def _check_connection(self, fs):
marker_file_name = self._get_marker_file_name()
try:
marker_file = fs.ls(marker_file_name, detail=False)
if not marker_file:
fs.touch(marker_file_name)
except FileNotFoundError:
fs.touch(marker_file_name)
return True

@property
def fs(self) -> fsspec.AbstractFileSystem:
"""Get the fsspec filesystem for this backend."""
self.ensure_one()
if not self.__fs:
self.__fs = self._get_filesystem()
if not tools.config["test_enable"]:
# Check whether we need to invalidate FS cache or not.
# Use a marker file to limit the scope of the LS command for performance.
try:
self._check_connection(self.__fs)
except Exception as e:
self.__fs.clear_instance_cache()
raise e
return self.__fs

def _get_filesystem_storage_path(self) -> str:
Expand Down Expand Up @@ -433,7 +454,7 @@ def delete(self, relative_path) -> None:

def action_test_config(self) -> None:
try:
self.fs.ls("", detail=False)
self._check_connection(self.__fs)
title = _("Connection Test Succeeded!")
message = _("Everything seems properly set up!")
msg_type = "success"
Expand Down
2 changes: 1 addition & 1 deletion fs_storage/readme/USAGE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ When you create a new backend, you must specify the following:
* The protocol options. These are the options that will be passed to the
fsspec python package when creating the filesystem. These options depend
on the protocol used and are described in the fsspec documentation.
* Resolve env vars. This options resolves the protocol options values starting
* Resolve env vars. This options resolves the protocol options values starting
with $ from environment variables

Some protocols defined in the fsspec package are wrappers around other
Expand Down
1 change: 1 addition & 0 deletions fs_storage/readme/newsfragments/320.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Invalidate FS filesystem object cache when the connection fails, forcing a reconnection.
3 changes: 2 additions & 1 deletion fs_storage/static/description/index.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
Expand Down Expand Up @@ -366,7 +367,7 @@ <h1 class="title">Filesystem Storage Backend</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:f7f1c906045d3f8e370a9b1a9d952f9df4dc14ed1a3003b4370f1807993a64cd
!! source digest: sha256:d76c1c7778c0c2f02c33b8d9852971df449268a7e5941c6d82483d99486b91e4
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/storage/tree/16.0/fs_storage"><img alt="OCA/storage" src="https://img.shields.io/badge/github-OCA%2Fstorage-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/storage-16-0/storage-16-0-fs_storage"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/storage&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This addon is a technical addon that allows you to define filesystem like
Expand Down

0 comments on commit f3b8084

Please sign in to comment.