I would like to use Powershell filewatcher to monitor an azure file share to lock a file that is currently uploading until it has completed uploading. I have another function that copies the uploaded files to other file shares and I don't want the copy file function to copy a file before it has been completely uploaded successfully. Is this even possible. Someone suggested acquiring a lease file. Does anyone have an example of how to do this in Powershell.
Asked
Active
Viewed 119 times
0
-
1This is a well-researched problem called [Producer-Consumer problem](https://en.wikipedia.org/wiki/Producer%E2%80%93consumer_problem). Several solutions exist on different use cases. – vonPryz Sep 15 '20 at 10:41
-
Thanks vonPryz, I guess I'm just looking for something that can confirms a) the file has no open handles b) the files is not currently open for writing by the sender ftp, sftp or copy. How can I be 100% sure the file I'm about to copy/move is complete? – vbquest Sep 15 '20 at 11:30
1 Answers
0
You could use Get-AzStorageFileHandle
Get-AzStorageFileHandle
[-ShareName] <String>
[[-Path] <String>]
[-Recursive]
[-Context <IStorageContext>]
[-ServerTimeoutPerRequest <Int32>]
[-ClientTimeoutPerRequest <Int32>]
[-DefaultProfile <IAzureContextContainer>]
[-ConcurrentTaskCount <Int32>]
[-IncludeTotalCount]
[-Skip <UInt64>]
[-First <UInt64>]
[<CommonParameters>]
Sample Snippet :
$storagecontext = New-AzStorageContext -StorageAccountName "<STORAGEACCOUNT NAME>" -StorageAccountKey "<KEY>"
Get-AzStorageFileHandle "<FILESHARENAME>" -Context $storagecontext -Recursive
Sample Output :
When I ran the command i was copying the search.py command
If you see a specific directory, coming up in the above commandlet you could safely assume that there is a operation happening in the directory and you could skip the directory from copying.

Satya V
- 3,811
- 1
- 6
- 9