Skip to content

store lock files in temporary directory #273

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 23, 2021

Conversation

tomerd
Copy link
Contributor

@tomerd tomerd commented Dec 22, 2021

motivation: local file system store lock files next to the file being locked and never cleans them up

changes:

  • add a tempDirectory to FileSystem protocol
  • update determineTempDirectory to use tempDirectory from localFileSystem
  • move logic to handle local file system locks to FileLock and call it from localFileSystem
  • expose an API on FileLock to create local file system locks, which by default uses the temp directory to store lock files, using the file-to-lock path and name to construct the lock file name
  • move local file system lock logic to use the new FileLock API
  • add tests

rdar://86644116

motivation: local file system store lock files next to the file being locked and never cleans them up

changes:
* add a tempDirectory to FileSystem protocol
* update determineTempDirectory to use tempDirectory from localFileSystem
* move logic to handle local file system locks to FileLock and call it from localFileSystem
* expose an API on FileLock to create local file system locks, which by default uses the temp directory to store lock files, using the file-to-lock path and name to construct the lock file name
* move local file system lock logic to use the new FileLock API
* add tests

rdar://86644116
@tomerd
Copy link
Contributor Author

tomerd commented Dec 22, 2021

@tomerd tomerd added the ready Author believes the PR is ready to be merged & any feedback has been addressed label Dec 22, 2021
throw FileSystemError(.notDirectory, lockFilesDirectory)
}
// use the parent path to generate unique filename in temp
var lockFileName = (resolveSymlinks(fileToLock.parentDirectory).appending(component: fileToLock.basename)).components.joined(separator: "_")
Copy link
Contributor

Choose a reason for hiding this comment

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

There's somewhat of a risk of overflow here since most operating systems / file systems have a much shorter file name limit than path limit. I don't know if that will be an issue in practice — an alternate approach to consider here might be to hash all the but the last n components of the path, which should still be indicative of what the lock file refers to.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we can also re-root the path into temp a potential solution. would that be better than what we have here now?

@tomerd tomerd merged commit bc0d6a7 into swiftlang:main Dec 23, 2021
tomerd added a commit to tomerd/swift-tools-support-core that referenced this pull request Dec 23, 2021
motivation: local file system store lock files next to the file being locked and never cleans them up

changes:
* add a tempDirectory to FileSystem protocol
* update determineTempDirectory to use tempDirectory from localFileSystem
* move logic to handle local file system locks to FileLock and call it from localFileSystem
* expose an API on FileLock to create local file system locks, which by default uses the temp directory to store lock files, using the file-to-lock path and name to construct the lock file name
* move local file system lock logic to use the new FileLock API
* add tests

rdar://86644116
tomerd added a commit that referenced this pull request Dec 23, 2021
motivation: local file system store lock files next to the file being locked and never cleans them up

changes:
* add a tempDirectory to FileSystem protocol
* update determineTempDirectory to use tempDirectory from localFileSystem
* move logic to handle local file system locks to FileLock and call it from localFileSystem
* expose an API on FileLock to create local file system locks, which by default uses the temp directory to store lock files, using the file-to-lock path and name to construct the lock file name
* move local file system lock logic to use the new FileLock API
* add tests

rdar://86644116
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready Author believes the PR is ready to be merged & any feedback has been addressed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants