Locks

A Lock can be used by your custom-developed applications to implement file locking and concurrency features. These locks are advisory, meaning that while a lock can be created, it does not prevent other API requests from being processed concurrently. You are responsible for checking locks prior to accessing a file.

The lock feature is designed to emulate the locking functionality provided by WebDAV. For a deeper understanding of how the lock mechanism works, refer to the WebDAV specification, which outlines how these endpoints function.

Files.com's WebDAV offering and desktop app leverage this locking API to manage concurrent file operations, ensuring consistency when multiple users or systems interact with the same files. It is not used within the Files.com web interface.

The optional owner parameter is a descriptive label, not the lock creator or a grant of permission. It can be set when creating a lock; refreshing a lock or replacing its token preserves it.

To refresh only an existing lock or replace its token, send expected_token, token, and timeout to the create endpoint. Set token to expected_token to refresh, or to a different value to replace. The expected token must identify an existing, unexpired lock on that path, and the caller must have permission to modify it. The token check and update happen together; invalid replacement values leave the stored lock unchanged.

A missing, expired, or mismatched expected token returns processing-failure/resource-locked with data.lock_token containing an active token on that path, or an empty string when none exists. Omitting expected_token retains the existing acquire-or-refresh behavior. Shared locks retain their existing semantics.

List Locks by Path

SDK Method

files_sdk.lock.list_for()

Return Object

ListObj[Lock]

Authorization Requirement

Available to all authenticated keys or sessions.

Method Arguments

ArgumentDescription
path
string
Required
Path to operate on.
include_children
boolean
Include locks from children objects?

Additional Arguments

Example Request

import files_sdk

try:
  locks = files_sdk.lock.list_for(path, {
    "include_children": False
  })
  for lock in locks.auto_paging_iter():
    print(lock.get_attributes())
except files_sdk.error.NotAuthenticatedError as err:
  print(f"Authentication Error Occurred ({type(err).__name__}):", err)
except files_sdk.error.Error as err:
  print(f"Unknown Error Occurred ({type(err).__name__}):", err)

Create Lock

SDK Method

files_sdk.lock.create()

Return Object

Lock

Authorization Requirement

Available to all authenticated keys or sessions.

Method Arguments

ArgumentDescription
path
string
Required
Path
token
string
Lock token. With expected_token, use the same value to refresh or a different value to replace the existing token.
expected_token
string
Require this existing, unexpired token before refreshing or replacing a lock. Set token to the same value to refresh, or a different value to replace.
allow_access_by_any_user
boolean
Can lock be modified by users other than its creator?
exclusive
boolean
Is lock exclusive?
recursive
boolean
Does lock apply to subfolders?
owner
string
Arbitrary descriptive label for the lock. Does not change the lock creator or permissions.
timeout
int64
Lock timeout in seconds

Example Request

import files_sdk

try:
  lock = files_sdk.lock.create(path, {
    "token": "17c54824e9931a4688ca032d03f6663c"
  })
  # Operate on lock
except files_sdk.error.NotAuthenticatedError as err:
  print(f"Authentication Error Occurred ({type(err).__name__}):", err)
except files_sdk.error.Error as err:
  print(f"Unknown Error Occurred ({type(err).__name__}):", err)

Delete Lock

SDK Method

lock.delete()

Return Object

No return value.

Authorization Requirement

Available to all authenticated keys or sessions.

Method Arguments

ArgumentDescription
token
string
Required
Lock token

Example Request

import files_sdk

try:
  lock = next(files_sdk.lock.list_for(path).auto_paging_iter(), None)
  if lock is not None:
    lock.delete({
      "token": "token"
    })
except files_sdk.error.NotAuthenticatedError as err:
  print(f"Authentication Error Occurred ({type(err).__name__}):", err)
except files_sdk.error.Error as err:
  print(f"Unknown Error Occurred ({type(err).__name__}):", err)

The Lock Object

Some of the methods above return a Lock object. The attributes of this object are listed below.

AttributeDescription
path
string
Path. This must be slash-delimited, but it must neither start nor end with a slash. Maximum of 5000 characters.
timeout
int64
Lock timeout in seconds
depth
string
recursive
boolean
Does lock apply to subfolders?
owner
string
Arbitrary descriptive label for the lock. Does not change the lock creator or permissions.
scope
string
exclusive
boolean
Is lock exclusive?
token
string
Lock token. Use to release lock.
type
string
allow_access_by_any_user
boolean
Can lock be modified by users other than its creator?
user_id
int64
Lock creator user ID
username
string
Lock creator username