Image:Utilities.sh
From NITRC Wiki
Utilities.sh (file size: 4 KB, MIME type: application/x-sh)
This (ba)sh script defines some useful functions for dependency checking and file locking.
Dependency checking is implemented in function "needs_update", which is called with two or more parameters (all paths to files or directories). The first parameter is the target file, which depends on the remaining files listed as parameters. If one of the prerequisite files is more recent than the target files, then the function returns "true", i.e., the target file needs to be updated. Otherwise, the function returns "false", i.e., the target file is up to date w.r.t. the given dependencies.
Example:
if needs_update target source1 source 2; then cat source1 source2 > target fi
The file locking (which tries hard to be NFS-safe, although it isn't completely) is implemented in two functions:
"lockfile_create" creates a lock for a given path in the file system, which is typically a target file that is being generated. If the function returns "true", locking was successful and processing should proceed. If the function returns false, locking failed (e.g., because another process has already locked the same file), and processing should skip this target file.
If a lock was successfully acquired, it must subsequently be freed (i.e., deleted) by calling "lockfile_delete".
Example:
if lockfile_create target; then echo "Hello!" > target lockfile_delete target fi
Finally, there is a combination function, "needs_update_and_lock," which is called exactly like "needs_update", but attempts to acquire a lock on the target file in case it needs to be updated.
Example:
if needs_update_and_lock target src1 src2; then cat src1 src2 > target lockfile_delete target fi
File history
Click on a date/time to view the file as it appeared at that time.
| Date/Time | User | Dimensions | File size | Comment | |
|---|---|---|---|---|---|
| current | 18:39, 8 April 2010 | Moderator (Talk | contribs) | 4 KB | This (ba)sh script defines some useful functions for dependency checking and file locking. Dependency checking is implemented in function "needs_update", which is called with two or more parameters (all paths to files or directories). The first parameter is the target file, which depends on the remaining files listed as parameters. If one of the prerequisite files is more recent than the target files, then the function returns "true", i.e., the target file needs to be updated. Otherwise, the function returns "false", i.e., the target file is up to date w.r.t. the given dependencies. Example: if needs_update target source1 source 2; then cat source1 source2 > target fi The file locking (which tries hard to be NFS-safe, although it isn't completely) is implemented in two functions: "lockfile_create" creates a lock for a given path in the file system, which is typically a target file that is being generated. If the function returns "true", locking was successful and processing should proceed. If the function returns false, locking failed (e.g., because another process has already locked the same file), and processing should skip this target file. If a lock was successfully acquired, it must subsequently be freed (i.e., deleted) by calling "lockfile_delete". Example: if lockfile_create target; then echo "Hello!" > target lockfile_delete target fi Finally, there is a combination function, "needs_update_and_lock," which is called exactly like "needs_update", but attempts to acquire a lock on the target file in case it needs to be updated. Example: if needs_update_and_lock target src1 src2; then cat src1 src2 > target lockfile_delete target fi |
- Edit this file using an external application
See the setup instructions for more information.
Links
There are no pages that link to this file.








