Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions sdk/storage/azure-storage-file/HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ To use a directory_url, the method `from_directory_url` must be used.
- `set_share_access_policy` has required parameter `signed_identifiers`.
- NoRetry policy has been removed. Use keyword argument `retry_total=0` for no retries.
- Removed types that were accidentally exposed from two modules. Only `FileServiceClient`, `ShareClient`, `DirectoryClient` and `FileClient` should be imported from azure.storage.file.aio
- NoRetry policy has been removed. Use keyword argument `retry_total=0` for no retries.
- Some parameters have become keyword only, rather than positional. Some examples include:
- `loop`
- `max_concurrency`
Expand All @@ -27,7 +26,12 @@ the following APIs:
- upload_range_from_url
- clear_range
- get_ranges
- `close_handles` renamed to `begin_close_handles`
- `FileClient.close_handles` and `DirectoryClient.close_handles` have both been replaced by two functions each; `close_handle(handle)` and `close_all_handles()`. These functions are blocking and return integers (the number of closed handles) rather than polling objects.

**New features**

- `ResourceTypes`, `NTFSAttributes`, and `Services` now have method `from_string` which takes parameters as a string.


## Version 12.0.0b4:

Expand Down
66 changes: 0 additions & 66 deletions sdk/storage/azure-storage-file/azure/storage/file/_polling.py

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
# --------------------------------------------------------------------------

import functools
import time
from typing import ( # pylint: disable=unused-import
Optional, Union, Any, Dict, TYPE_CHECKING
)

from azure.core.polling import async_poller
from azure.core.async_paging import AsyncItemPaged

from azure.core.tracing.decorator import distributed_trace
Expand All @@ -26,7 +26,6 @@
from .._shared.response_handlers import return_response_headers, process_storage_error
from .._deserialize import deserialize_directory_properties
from ..directory_client import DirectoryClient as DirectoryClientBase
from ._polling_async import CloseHandlesAsync
from .file_client_async import FileClient
from .models import DirectoryPropertiesPaged, HandlesPaged

Expand Down Expand Up @@ -108,7 +107,7 @@ def get_file_client(self, file_name, **kwargs):
:param file_name:
The name of the file.
:returns: A File Client.
:rtype: ~azure.storage.file.file_client.FileClient
:rtype: ~azure.storage.file.FileClient
"""
if self.directory_path:
file_name = self.directory_path.rstrip('/') + "/" + file_name
Expand All @@ -126,7 +125,7 @@ def get_subdirectory_client(self, directory_name, **kwargs):
:param str directory_name:
The name of the subdirectory.
:returns: A Directory Client.
:rtype: ~azure.storage.file.aio.directory_client_async.DirectoryClient
:rtype: ~azure.storage.file.aio.DirectoryClient

.. admonition:: Example:

Expand Down Expand Up @@ -262,50 +261,79 @@ def list_handles(self, recursive=False, **kwargs):
page_iterator_class=HandlesPaged)

@distributed_trace_async
async def close_handles(
self, handle=None, # type: Union[str, HandleItem]
recursive=False, # type: bool
**kwargs # type: Any
):
# type: (...) -> int
"""Close open file handles.
async def close_handle(self, handle, **kwargs):
# type: (Union[str, HandleItem], Any) -> int
"""Close an open file handle.

:param handle:
Optionally, a specific handle to close. The default value is '*'
which will attempt to close all open handles.
A specific handle to close.
:type handle: str or ~azure.storage.file.Handle
:param bool recursive:
Boolean that specifies if operation should apply to the directory specified by the client,
its files, its subdirectories and their files. Default value is False.
:keyword int timeout:
The timeout parameter is expressed in seconds.
:returns: The number of file handles that were closed.
:returns:
The total number of handles closed. This could be 0 if the supplied
handle was not found.
:rtype: int
"""
timeout = kwargs.pop('timeout', None)
try:
handle_id = handle.id # type: ignore
except AttributeError:
handle_id = handle or '*'
command = functools.partial(
self._client.directory.force_close_handles,
handle_id,
timeout=timeout,
sharesnapshot=self.snapshot,
recursive=recursive,
cls=return_response_headers,
**kwargs)
handle_id = handle
Comment thread
annatisch marked this conversation as resolved.
if handle_id == '*':
raise ValueError("Handle ID '*' is not supported. Use 'close_all_handles' instead.")
try:
start_close = await command()
response = await self._client.directory.force_close_handles(
handle_id,
marker=None,
recursive=None,
sharesnapshot=self.snapshot,
cls=return_response_headers,
**kwargs
)
return response.get('number_of_handles_closed', 0)
except StorageErrorException as error:
process_storage_error(error)

polling_method = CloseHandlesAsync(self._config.copy_polling_interval)
return await async_poller(
command,
start_close,
None,
polling_method)
@distributed_trace_async
async def close_all_handles(self, recursive=False, **kwargs):
# type: (bool, Any) -> int
"""Close any open file handles.

This operation will block until the service has closed all open handles.

:param bool recursive:
Boolean that specifies if operation should apply to the directory specified by the client,
its files, its subdirectories and their files. Default value is False.
:keyword int timeout:
The timeout parameter is expressed in seconds.
:returns: The total number of handles closed.
:rtype: int
"""
timeout = kwargs.pop('timeout', None)
start_time = time.time()

try_close = True
continuation_token = None
total_handles = 0
while try_close:
try:
response = await self._client.directory.force_close_handles(
handle_id='*',
timeout=timeout,
marker=continuation_token,
recursive=recursive,
sharesnapshot=self.snapshot,
cls=return_response_headers,
**kwargs
)
except StorageErrorException as error:
process_storage_error(error)
continuation_token = response.get('marker')
try_close = bool(continuation_token)
total_handles += response.get('number_of_handles_closed', 0)
if timeout:
timeout = max(0, timeout - (time.time() - start_time))
return total_handles

@distributed_trace_async
async def get_directory_properties(self, **kwargs):
Expand Down
Loading