Skip to content

Conversation

@xhernandez
Copy link
Contributor

This PR adds support for locking and unlocking byte ranges in files.

@codecov
Copy link

codecov bot commented Jan 27, 2025

Codecov Report

Attention: Patch coverage is 94.73684% with 2 lines in your changes missing coverage. Please review.

Project coverage is 99.03%. Comparing base (7dfbd01) to head (9983bff).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/smbprotocol/open.py 94.73% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #309      +/-   ##
==========================================
- Coverage   99.06%   99.03%   -0.04%     
==========================================
  Files          24       24              
  Lines        5146     5184      +38     
==========================================
+ Hits         5098     5134      +36     
- Misses         48       50       +2     
Flag Coverage Δ
arm64 68.22% <55.26%> (-0.10%) ⬇️
macOS 68.22% <55.26%> (-0.10%) ⬇️
py3.10 98.99% <94.73%> (-0.04%) ⬇️
py3.11 98.99% <94.73%> (-0.04%) ⬇️
py3.12 98.99% <94.73%> (-0.04%) ⬇️
py3.13 98.99% <94.73%> (-0.04%) ⬇️
py3.8 98.99% <94.73%> (-0.04%) ⬇️
py3.9 99.03% <94.73%> (-0.04%) ⬇️
ubuntu 96.83% <94.73%> (-0.02%) ⬇️
windows 98.95% <94.73%> (-0.04%) ⬇️
x64 99.03% <94.73%> (-0.04%) ⬇️
x86 98.95% <94.73%> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Owner

@jborean93 jborean93 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the CI failures is because I didn't bump the version so it is still pulling in the version from PyPI. I've just merged #310 which should solve that. You probably need to rebase to get those latest changes sorry.

self.file_attributes = c_resp["file_attributes"].get_value()
return c_resp

def lock(self, locks, lsn=0, lsi=0, wait=True, send=True):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have a particular reason for exposing the sequence and index numbers right now? The protocol docs somewhat indicate they are used for some global state that I don't fully understand and am wondering if it is just best to keep it at 0 and expose it when requested by someone.

https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-smb2/06d42500-2ead-4659-8af2-86dcaec5286e

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I exposed it because it's something that clients may use for dialects > 2.0.2. I don't fully understand it either, but I wanted to be able to reproduce any sequence of operations that a client may send to a server (the reason I implemented the LOCK operation was to reproduce an issue we detected with Samba, though it didn't use lsn/lsi).

I think it doesn't hurt to have them, and they may become useful in some cases. The protocol has them, so I don't see why we should hide them. In normal cases they won't be used, so the default value of 0 will be applied.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough, I didn't want to paint us into a corner but it's probably not going to be a problem. We can always deprecate things if we want to take away the ability to set these if we ever find out it should be calculated internally somehow but I doubt that would happen.

lock["locks"] = locks

if self.connection.dialect > Dialects.SMB_2_0_2:
lock["lock_sequence"] = (lsn << 28) + lsi
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we do decide to expose this, we should ensure that lsn fits into the 28 bits and lsi isn't more than 4 bits. If they are then we should raise a ValueError.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. I'll add those checks.

Signed-off-by: Xavi Hernandez <xhernandez@redhat.com>
Signed-off-by: Xavi Hernandez <xhernandez@redhat.com>
@jborean93
Copy link
Owner

Thanks for implementing this feature!

@jborean93 jborean93 merged commit 9f3e83e into jborean93:master Jan 28, 2025
26 of 28 checks passed
@xhernandez xhernandez deleted the lock branch January 28, 2025 18:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants