summaryrefslogtreecommitdiff
path: root/src/validators/file-exists
diff options
context:
space:
mode:
authorJohn Estabrook <jestabro@vyos.io>2022-12-14 09:07:40 -0600
committerGitHub <noreply@github.com>2022-12-14 09:07:40 -0600
commit92aa324fef80bdb0bcb3e93feba2f4e2aa787d38 (patch)
tree7dc4a5d1ff463c9502fb5c4dfd0f298f3f29d35c /src/validators/file-exists
parent6095dfec48cefbdafe77d49325a122acfad1c372 (diff)
parent046bb9ccd56ac5e97c638bb4a9ca856d3d36026a (diff)
downloadvyos-1x-92aa324fef80bdb0bcb3e93feba2f4e2aa787d38.tar.gz
vyos-1x-92aa324fef80bdb0bcb3e93feba2f4e2aa787d38.zip
Merge pull request #1706 from jestabro/validator-file-exists
validators: T4798: replace python file-exists validator with file-path
Diffstat (limited to 'src/validators/file-exists')
-rwxr-xr-xsrc/validators/file-exists61
1 files changed, 0 insertions, 61 deletions
diff --git a/src/validators/file-exists b/src/validators/file-exists
deleted file mode 100755
index 5cef6b199..000000000
--- a/src/validators/file-exists
+++ /dev/null
@@ -1,61 +0,0 @@
-#!/usr/bin/env python3
-#
-# Copyright (C) 2019 VyOS maintainers and contributors
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License version 2 or later as
-# published by the Free Software Foundation.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-#
-# Description:
-# Check if a given file exists on the system. Used for files that
-# are referenced from the CLI and need to be preserved during an image upgrade.
-# Warn the user if these aren't under /config
-
-import os
-import sys
-import argparse
-
-
-def exit(strict, message):
- if strict:
- sys.exit(f'ERROR: {message}')
- print(f'WARNING: {message}', file=sys.stderr)
- sys.exit()
-
-
-if __name__ == '__main__':
- parser = argparse.ArgumentParser()
- parser.add_argument("-d", "--directory", type=str, help="File must be present in this directory.")
- parser.add_argument("-e", "--error", action="store_true", help="Tread warnings as errors - change exit code to '1'")
- parser.add_argument("file", type=str, help="Path of file to validate")
-
- args = parser.parse_args()
-
- #
- # Always check if the given file exists
- #
- if not os.path.exists(args.file):
- exit(args.error, f"File '{args.file}' not found")
-
- #
- # Optional check if the file is under a certain directory path
- #
- if args.directory:
- # remove directory path from path to verify
- rel_filename = args.file.replace(args.directory, '').lstrip('/')
-
- if not os.path.exists(args.directory + '/' + rel_filename):
- exit(args.error,
- f"'{args.file}' lies outside of '{args.directory}' directory.\n"
- "It will not get preserved during image upgrade!"
- )
-
- sys.exit()