Compare commits

...

4 Commits

Author SHA1 Message Date
BodgeMaster cc40df65d3 added link to the list of implemented subcommands (forgot to earlier) 2021-12-20 11:49:56 +01:00
BodgeMaster b5c9d92ca8 implemented link subcommand 2021-12-20 11:48:54 +01:00
BodgeMaster b9dc47d0e9 updated license 2021-12-20 05:30:26 +01:00
BodgeMaster d4fed7aee4 forgot to remove TODO, fixed 2021-12-20 03:17:33 +01:00
2 changed files with 50 additions and 7 deletions

View File

@ -10,7 +10,12 @@ this list of conditions and the following disclaimer.
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Don't be a dick.
3. All advertising materials mentioning features or use of this software must
clearly acknowledge that this software is being used unless software from more
than two other projects and/or vendors is being included in the distribution of
the advertised product.
4. Don't be an asshole.
THIS SOFTWARE IS PROVIDED BY COPYRIGHT HOLDER "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF

View File

@ -200,6 +200,8 @@ if __name__ == "__main__":
#TODO: clarification of <> and []
#TODO: subcommand to change container settings
VALID_COMMANDS=["create", "add", "remove", "search", "lookup", "link", "check", "update", "fix", "help"]
#TODO: (*fully) implemented subcommands: *create, *add, *lookup, *link, *help
#TODO: unimplemented subcommands: remove, search, check, update, fix
try:
command = sys.argv[1].split("+")
@ -212,11 +214,6 @@ if __name__ == "__main__":
print(USAGE, file=sys.stderr)
sys.exit(USAGE_ERROR)
# help subcommand
if command[0] == "help":
print(USAGE)
sys.exit(0)
# create subcommand: create a new directory containing a folder for stored objects, one for parity files and one for
# arguments: <storage directory> [parity=<on|off>] [parity-bytes=<number of bytes for each parity byte>] [checksum-algorithm=<algorithm>] [compress=<on|off>]
if command[0] == "create":
@ -349,7 +346,6 @@ if __name__ == "__main__":
# unique - return error if not found or multiple found
# hash - perform lookup by hash
# tags - perform lookup by tag or set of tags
#TODO: modifiers: first unique
if command[0] == "lookup":
if len(sys.argv)<4:
print("Too few arguments!", file=sys.stderr)
@ -401,6 +397,48 @@ if __name__ == "__main__":
else:
print(json.dumps(lookup_results))
# link subcommand: add a symlink in <location> that points to the referenced file
# arguments:
# <storage directory> <hash> <location>
if command[0] == "link":
if len(sys.argv)<5:
print("Too few arguments!", file=sys.stderr)
print(USAGE, file=sys.stderr)
sys.exit(USAGE_ERROR)
storage_directory = sys.argv[2]
file_hash = sys.argv[3]
link_location = sys.argv[4]
status, parity, parity_bytes, checksum_algorithm, compress = load_container_settings(storage_directory)
if not status==0:
if status==PATH_ERROR:
print("Invalid storage directory!", file=sys.stderr)
print(USAGE, file=sys.stderr)
if status==GENERAL_ERROR:
print("Verifying container settings failed.", file=sys.stderr)
sys.exit(status)
if file_hash_or_path_is_known_hash(storage_directory, file_hash, compress):
if os.path.isdir(os.sep.join(link_location.split(os.sep)[:-1])):
if os.path.exists(link_location):
print(link_location+": file already exists.", file=sys.stderr)
sys.exit(GENERAL_ERROR)
else:
suffix = ""
if compress:
suffix = ".xz"
object_path = os.path.join(storage_directory, "objects", file_hash+suffix)
os.symlink(object_path, link_location)
print(link_location+" -> "+object_path)
else:
print("Parent directory "+os.sep.join(link_location.split(os.sep)[:-1])+" does not exist.", file=sys.stderr)
sys.exit(GENERAL_ERROR)
# help subcommand
if command[0] == "help":
print(USAGE)
sys.exit(0)
# this line is here to work around a bug in Xed