LfsPointerFileValidator.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <AzCore/std/containers/set.h>
  10. #include <AzCore/std/containers/vector.h>
  11. #include <AzCore/std/string/string.h>
  12. namespace AssetProcessor
  13. {
  14. //! Class for validating LFS pointer files based on the provided .gitattributes files.
  15. class LfsPointerFileValidator
  16. {
  17. public:
  18. LfsPointerFileValidator() = default;
  19. LfsPointerFileValidator(const AZStd::vector<AZStd::string>& scanDirectories);
  20. //! Read the .gitattributes file under the specified directory to retrieve the LFS pointer file path patterns.
  21. //! @param directory Directory to find the .gitattributes file.
  22. void ParseGitAttributesFile(const AZStd::string& directory);
  23. //! Check whether the specified file is an LFS pointer file.
  24. //! @param filePath Path to the file to check.
  25. //! @return Return true if the file is an LFS pointer file.
  26. bool IsLfsPointerFile(const AZStd::string& filePath);
  27. //! Retrieve the LFS pointer file path patterns.
  28. //! @return List of LFS pointer file path patterns.
  29. AZStd::set<AZStd::string> GetLfsPointerFilePathPatterns();
  30. private:
  31. //! Check whether the file content matches the LFS pointer file content rules.
  32. //! @param filePath Path to the file to check.
  33. //! @return Return true if the file content matches all the LFS pointer file content rules.
  34. bool CheckLfsPointerFileContent(const AZStd::string& filePath);
  35. //! Check whether the specified file path matches any of the known LFS pointer file path patterns.
  36. //! @param filePath Path to the file to check.
  37. //! @return Return true if the file matches any of the known LFS pointer file path patterns.
  38. bool CheckLfsPointerFilePathPattern(const AZStd::string& filePath);
  39. AZStd::set<AZStd::string> m_lfsPointerFilePatterns; //!< List of the known LFS pointer file path patterns.
  40. };
  41. }