diff --git a/.github/workflows/codeql.yaml b/.github/workflows/codeql.yaml
index aba3ff1..2ffe0b3 100644
--- a/.github/workflows/codeql.yaml
+++ b/.github/workflows/codeql.yaml
@@ -66,14 +66,14 @@ jobs:
steps:
- id: checkout_repository
name: Checkout repository
- uses: actions/checkout@v4
+ uses: actions/checkout@v5
with:
lfs: false
submodules: recursive
- id: codeql_init
name: Initialize CodeQL
- uses: github/codeql-action/init@v3
+ uses: github/codeql-action/init@v4
with:
source-root: ${{ env.GOHOME }}
languages: ${{ matrix.language }}
@@ -81,6 +81,6 @@ jobs:
- id: codeql_analyze
name: Perform CodeQL Analysis
- uses: github/codeql-action/analyze@v3
+ uses: github/codeql-action/analyze@v4
with:
category: "/language:${{matrix.language}}"
diff --git a/.github/workflows/devenv-update.yaml b/.github/workflows/devenv-update.yaml
index ea18fe7..8df7a4c 100644
--- a/.github/workflows/devenv-update.yaml
+++ b/.github/workflows/devenv-update.yaml
@@ -61,7 +61,7 @@ jobs:
steps:
- id: checkout_repository
name: Checkout repository
- uses: actions/checkout@v4
+ uses: actions/checkout@v5
with:
lfs: false
submodules: recursive
diff --git a/.github/workflows/devenv.yaml b/.github/workflows/devenv.yaml
index 158ca27..a97a6ee 100644
--- a/.github/workflows/devenv.yaml
+++ b/.github/workflows/devenv.yaml
@@ -18,7 +18,6 @@ on: # yamllint disable-line rule:truthy
- devenv.nix
- devenv.yaml
- devenv.lock
- - devenv/**
- src/**
concurrency:
@@ -66,7 +65,7 @@ jobs:
steps:
- id: checkout_repository
name: Checkout repository
- uses: actions/checkout@v4
+ uses: actions/checkout@v5
with:
lfs: false
submodules: recursive
diff --git a/.github/workflows/go.yaml b/.github/workflows/go.yaml
index 24b31e0..f6513d7 100644
--- a/.github/workflows/go.yaml
+++ b/.github/workflows/go.yaml
@@ -54,9 +54,8 @@ jobs:
fail-fast: false
matrix:
go-version:
- - "1.22"
- - "1.23"
- "1.24"
+ - "1.25"
go-os:
- "linux"
- "darwin"
@@ -69,14 +68,14 @@ jobs:
steps:
- id: checkout_repository
name: Checkout repository
- uses: actions/checkout@v4
+ uses: actions/checkout@v5
with:
lfs: false
submodules: recursive
- id: go_setup
name: Set up Go (${{ matrix.go-version }})
- uses: actions/setup-go@v5
+ uses: actions/setup-go@v6
with:
check-latest: true
go-version: ${{ matrix.go-version }}
diff --git a/.github/workflows/linter.yaml b/.github/workflows/linter.yaml
index 3ddf87d..5532462 100644
--- a/.github/workflows/linter.yaml
+++ b/.github/workflows/linter.yaml
@@ -43,7 +43,7 @@ jobs:
steps:
- id: checkout_repository
name: Checkout repository with all history and tags
- uses: actions/checkout@v4
+ uses: actions/checkout@v5
env:
GITHUB_TOKEN: ${{ secrets.SUPER_LINTER_TOKEN }}
with:
diff --git a/.github/workflows/nancy.yaml b/.github/workflows/nancy.yaml
index a024b3e..2d18f4e 100644
--- a/.github/workflows/nancy.yaml
+++ b/.github/workflows/nancy.yaml
@@ -63,16 +63,17 @@ jobs:
steps:
- id: checkout_repository
name: Checkout repository
- uses: actions/checkout@v4
+ uses: actions/checkout@v5
with:
lfs: false
submodules: recursive
- - id: test_go_sum
- name: Test for go.sum
+ - id: check_nancy
+ name: Check for Nancy run conditions
shell: bash
run: |
- cd ${{ env.GOHOME }}
+ # Condition 1. We need a go.sum file.
+ pushd ${{ env.GOHOME }}
if [ -f "go.sum" ];
then
echo "๐ go.sum file present, running Nancy."
@@ -82,12 +83,26 @@ jobs:
echo "๐ No go.sum file present, skipping Nancy."
echo "run_nancy=false" >> "$GITHUB_OUTPUT"
fi
+ popd
+ # Condition 2. We need OSS Index username and token.
+ if [ "${{ vars.OSS_INDEX_USERNAME }}" != '' ] && [ "${{ secrets.OSS_INDEX_TOKEN }}" != '' ];
+ then
+ echo "๐ OSS Index username and token present, running Nancy."
+ echo "run_nancy=true" >> "$GITHUB_OUTPUT"
+ else
+ echo "๐ OSS Index username or token missing, skipping Nancy."
+ echo "run_nancy=false" >> "$GITHUB_OUTPUT"
+ fi
- id: run_nancy
name: Run Nancy
- if: ${{ steps.test_go_sum.outputs.run_nancy == 'true' }}
+ if: steps.check_nancy.outputs.run_nancy == 'true'
uses: sonatype-nexus-community/nancy-github-action@main
with:
githubToken: ${{ secrets.GITHUB_TOKEN }}
nancyVersion: latest
- nancyCommand: sleuth --loud
+ nancyCommand: >-
+ sleuth
+ --username ${{ vars.OSS_INDEX_USERNAME }}
+ --token ${{ secrets.OSS_INDEX_TOKEN }}
+ --loud
diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml
index b555832..4c3090b 100644
--- a/.github/workflows/release.yaml
+++ b/.github/workflows/release.yaml
@@ -71,7 +71,7 @@ jobs:
- id: checkout_repository
name: Checkout Repository
- uses: actions/checkout@v4
+ uses: actions/checkout@v5
with:
lfs: false
submodules: none
@@ -119,7 +119,7 @@ jobs:
ARTIFACT_FILE_1="${{ env.ARTIFACT_PATH }}/bin/${{ env.REPO_NAME }}"
ARTIFACT_FILE_2="${{ env.ARTIFACT_PATH }}/bin/${{ matrix.goos }}_${{ matrix.goarch }}/${{ env.REPO_NAME }}"
- mkdir -p artifacts
+ mkdir -p artifacts
if [[ -f "${ARTIFACT_FILE_1}" ]];
then
@@ -185,7 +185,7 @@ jobs:
- id: checkout_repository
name: Checkout Repository
- uses: actions/checkout@v4
+ uses: actions/checkout@v5
with:
lfs: false
submodules: none
@@ -303,7 +303,7 @@ jobs:
- id: create_release
name: Create GitHub release
- uses: actions/github-script@v7
+ uses: actions/github-script@v8
if: steps.check_version_bump.outputs.CREATE_RELEASE == 'true'
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
@@ -426,7 +426,7 @@ jobs:
steps:
- id: checkout_repository
name: Checkout Repository
- uses: actions/checkout@v4
+ uses: actions/checkout@v5
with:
lfs: false
submodules: none
diff --git a/.github/workflows/trivy.yaml b/.github/workflows/trivy.yaml
index e1eba16..3eaa8bb 100644
--- a/.github/workflows/trivy.yaml
+++ b/.github/workflows/trivy.yaml
@@ -74,7 +74,7 @@ jobs:
steps:
- id: checkout_repository
name: Checkout repository
- uses: actions/checkout@v4
+ uses: actions/checkout@v5
with:
lfs: false
submodules: recursive
@@ -115,7 +115,7 @@ jobs:
- id: trivy_upload
name: Trivy (upload)
- uses: github/codeql-action/upload-sarif@v3
+ uses: github/codeql-action/upload-sarif@v4
with:
sarif_file: "trivy-results.sarif"
diff --git a/devenv.lock b/devenv.lock
index fc0124e..b75cdc5 100644
--- a/devenv.lock
+++ b/devenv.lock
@@ -3,10 +3,10 @@
"devenv": {
"locked": {
"dir": "src/modules",
- "lastModified": 1755039979,
+ "lastModified": 1760560333,
"owner": "cachix",
"repo": "devenv",
- "rev": "63db0a32cd767c2a9089fbaf24b0bb91c64c0652",
+ "rev": "0a4043938f540027e562c5a0feebbe6be872c3ea",
"type": "github"
},
"original": {
@@ -57,10 +57,10 @@
]
},
"locked": {
- "lastModified": 1754416808,
+ "lastModified": 1760392170,
"owner": "cachix",
"repo": "git-hooks.nix",
- "rev": "9c52372878df6911f9afc1e2a1391f55e4dfc864",
+ "rev": "46d55f0aeb1d567a78223e69729734f3dca25a85",
"type": "github"
},
"original": {
@@ -95,10 +95,10 @@
"nixpkgs": "nixpkgs"
},
"locked": {
- "lastModified": 1754078208,
+ "lastModified": 1759991118,
"owner": "nix-community",
"repo": "gomod2nix",
- "rev": "7f963246a71626c7fc70b431a315c4388a0c95cf",
+ "rev": "7f8d7438f5870eb167abaf2c39eea3d2302019d1",
"type": "github"
},
"original": {
@@ -142,10 +142,10 @@
},
"nixpkgs": {
"locked": {
- "lastModified": 1755042551,
+ "lastModified": 1760608560,
"owner": "NixOS",
"repo": "nixpkgs",
- "rev": "e4b54494cba4c82005d5fe3c0329a8f66fbfcff7",
+ "rev": "9c15c2a846a00eb6a98ac974b335ca7be2404311",
"type": "github"
},
"original": {
@@ -155,32 +155,17 @@
"type": "github"
}
},
- "nixpkgs-unstable": {
- "locked": {
- "lastModified": 1754990257,
- "owner": "nixos",
- "repo": "nixpkgs",
- "rev": "372d9eeeafa5b15913201e2b92e8e539ac7c64d1",
- "type": "github"
- },
- "original": {
- "owner": "nixos",
- "ref": "nixpkgs-unstable",
- "repo": "nixpkgs",
- "type": "github"
- }
- },
"nixpkgs_2": {
"locked": {
- "lastModified": 1754299112,
+ "lastModified": 1760346906,
"owner": "cachix",
"repo": "devenv-nixpkgs",
- "rev": "16c21c9f5c6fb978466e91182a248dd8ca1112ac",
+ "rev": "0b429772c9c9b6f96cca629371a3150eb3cf862d",
"type": "github"
},
"original": {
"owner": "cachix",
- "ref": "rolling",
+ "ref": "bump-rolling",
"repo": "devenv-nixpkgs",
"type": "github"
}
@@ -193,7 +178,6 @@
"mk-shell-bin": "mk-shell-bin",
"nix2container": "nix2container",
"nixpkgs": "nixpkgs_2",
- "nixpkgs-unstable": "nixpkgs-unstable",
"pre-commit-hooks": [
"git-hooks"
]
diff --git a/devenv.nix b/devenv.nix
index 3276d1f..2852747 100644
--- a/devenv.nix
+++ b/devenv.nix
@@ -2,14 +2,13 @@
pkgs,
config,
lib,
- inputs,
...
}:
let
# Variables
name = "nixos-installer";
- version = "0.1.5";
+ version = "0.1.6";
# Custom packages.
nixos-installer = import ./devenv/nixos-installer.nix {
@@ -20,16 +19,6 @@ let
inherit pkgs;
};
- # All available unstable packages.
- pkgsUnstable = import inputs.nixpkgs-unstable {
- config.allowUnfree = true;
- };
-
- # Installed unstable packages.
- unstablePackages = with pkgsUnstable; [
- #golangci-lint
- ];
-
# Common stable packages.
commonPackages = with pkgs; [
figlet
@@ -74,7 +63,6 @@ in
packages =
commonPackages
- ++ unstablePackages
++ lib.optionals (!config.container.isBuilding || config.name == "devenv") devPackages;
enterShell = ''
@@ -105,14 +93,12 @@ in
git-hooks = {
excludes = [
- ".cache"
- ".devenv"
- ".direnv"
- "src/vendor"
+ "src/vendor/"
];
hooks = {
beautysh.enable = false;
actionlint.enable = true;
+ action-validator.enable = true;
check-merge-conflicts.enable = true;
check-shebang-scripts-are-executable.enable = true;
check-symlinks.enable = true;
@@ -166,8 +152,15 @@ in
starship.enable = true;
enterTest = ''
- echo "Running tests"
+ echo -e "\nSTART: Running tests"
+
+ echo -e "\nTEST: Show git version"
git --version | grep --color=auto "${pkgs.git.version}"
+
+ echo -e "\nTEST: Show nix-installer version"
+ nixos-installer --version
+
+ echo -e "\nEND: Running tests"
'';
scripts = {
diff --git a/devenv.yaml b/devenv.yaml
index 35af34d..0bc77b4 100644
--- a/devenv.yaml
+++ b/devenv.yaml
@@ -2,9 +2,8 @@
# yaml-language-server: $schema=https://devenv.sh/devenv.schema.json
inputs:
nixpkgs:
- url: github:cachix/devenv-nixpkgs/rolling
- nixpkgs-unstable:
- url: github:nixos/nixpkgs/nixpkgs-unstable
+ #url: github:cachix/devenv-nixpkgs/rolling
+ url: github:cachix/devenv-nixpkgs/bump-rolling
nix2container:
url: github:nlewo/nix2container
inputs:
diff --git a/scripts/yolo.sh b/scripts/yolo.sh
index 34ff6d3..bacbb11 100755
--- a/scripts/yolo.sh
+++ b/scripts/yolo.sh
@@ -94,7 +94,7 @@ function detect_os() {
return 0
}
-# shellcheck disable=SC2317
+# shellcheck disable=SC2317,SC2329
function cleanup() {
msg "INFO" "๐งน Cleaning up temporary directory"
rm -rf "${TMP_DIR}" || {
diff --git a/src/go.mod b/src/go.mod
index ca02d4a..e6ca152 100644
--- a/src/go.mod
+++ b/src/go.mod
@@ -3,17 +3,16 @@ module github.com/MAHDTech/nixos-installer
go 1.24.1
require (
- github.com/go-playground/validator/v10 v10.27.0
+ github.com/go-playground/validator/v10 v10.28.0
gopkg.in/yaml.v3 v3.0.1
)
require (
- github.com/gabriel-vasile/mimetype v1.4.9 // indirect
+ github.com/gabriel-vasile/mimetype v1.4.10 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
- golang.org/x/crypto v0.41.0 // indirect
- golang.org/x/net v0.43.0 // indirect
- golang.org/x/sys v0.35.0 // indirect
- golang.org/x/text v0.28.0 // indirect
+ golang.org/x/crypto v0.43.0 // indirect
+ golang.org/x/sys v0.37.0 // indirect
+ golang.org/x/text v0.30.0 // indirect
)
diff --git a/src/go.sum b/src/go.sum
index 3a35a9f..b237198 100644
--- a/src/go.sum
+++ b/src/go.sum
@@ -1,29 +1,27 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
-github.com/gabriel-vasile/mimetype v1.4.9 h1:5k+WDwEsD9eTLL8Tz3L0VnmVh9QxGjRmjBvAG7U/oYY=
-github.com/gabriel-vasile/mimetype v1.4.9/go.mod h1:WnSQhFKJuBlRyLiKohA/2DtIlPFAbguNaG7QCHcyGok=
+github.com/gabriel-vasile/mimetype v1.4.10 h1:zyueNbySn/z8mJZHLt6IPw0KoZsiQNszIpU+bX4+ZK0=
+github.com/gabriel-vasile/mimetype v1.4.10/go.mod h1:d+9Oxyo1wTzWdyVUPMmXFvp4F9tea18J8ufA774AB3s=
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
-github.com/go-playground/validator/v10 v10.27.0 h1:w8+XrWVMhGkxOaaowyKH35gFydVHOvC0/uWoy2Fzwn4=
-github.com/go-playground/validator/v10 v10.27.0/go.mod h1:I5QpIEbmr8On7W0TktmJAumgzX4CA1XNl4ZmDuVHKKo=
+github.com/go-playground/validator/v10 v10.28.0 h1:Q7ibns33JjyW48gHkuFT91qX48KG0ktULL6FgHdG688=
+github.com/go-playground/validator/v10 v10.28.0/go.mod h1:GoI6I1SjPBh9p7ykNE/yj3fFYbyDOpwMn5KXd+m2hUU=
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
-golang.org/x/crypto v0.41.0 h1:WKYxWedPGCTVVl5+WHSSrOBT0O8lx32+zxmHxijgXp4=
-golang.org/x/crypto v0.41.0/go.mod h1:pO5AFd7FA68rFak7rOAGVuygIISepHftHnr8dr6+sUc=
-golang.org/x/net v0.43.0 h1:lat02VYK2j4aLzMzecihNvTlJNQUq316m2Mr9rnM6YE=
-golang.org/x/net v0.43.0/go.mod h1:vhO1fvI4dGsIjh73sWfUVjj3N7CA9WkKJNQm2svM6Jg=
-golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI=
-golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
-golang.org/x/text v0.28.0 h1:rhazDwis8INMIwQ4tpjLDzUhx6RlXqZNPEM0huQojng=
-golang.org/x/text v0.28.0/go.mod h1:U8nCwOR8jO/marOQ0QbDiOngZVEBB7MAiitBuMjXiNU=
+golang.org/x/crypto v0.43.0 h1:dduJYIi3A3KOfdGOHX8AVZ/jGiyPa3IbBozJ5kNuE04=
+golang.org/x/crypto v0.43.0/go.mod h1:BFbav4mRNlXJL4wNeejLpWxB7wMbc79PdRGhWKncxR0=
+golang.org/x/sys v0.37.0 h1:fdNQudmxPjkdUTPnLn5mdQv7Zwvbvpaxqs831goi9kQ=
+golang.org/x/sys v0.37.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
+golang.org/x/text v0.30.0 h1:yznKA/E9zq54KzlzBEAWn1NXSQ8DIp/NYMy88xJjl4k=
+golang.org/x/text v0.30.0/go.mod h1:yDdHFIX9t+tORqspjENWgzaCVXgk0yYnYuSZ8UzzBVM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
diff --git a/src/gomod2nix.toml b/src/gomod2nix.toml
index 31f73c4..d0de542 100644
--- a/src/gomod2nix.toml
+++ b/src/gomod2nix.toml
@@ -2,8 +2,8 @@ schema = 3
[mod]
[mod."github.com/gabriel-vasile/mimetype"]
- version = "v1.4.9"
- hash = "sha256-75uELLqb01djHTe7KdXvUidBK7SuejarYouEUuxaj8Q="
+ version = "v1.4.10"
+ hash = "sha256-ha8NJOAWcmEfQaybfNxyUupt0+zlWxoAKLjCacew43s="
[mod."github.com/go-playground/locales"]
version = "v0.14.1"
hash = "sha256-BMJGAexq96waZn60DJXZfByRHb8zA/JP/i6f/YrW9oQ="
@@ -11,23 +11,20 @@ schema = 3
version = "v0.18.1"
hash = "sha256-2/B2qP51zfiY+k8G0w0D03KXUc7XpWj6wKY7NjNP/9E="
[mod."github.com/go-playground/validator/v10"]
- version = "v10.27.0"
- hash = "sha256-S6RXBwCOaLUumtS1xucTzOPGxA9XuA3R8RNdGE7w2Qc="
+ version = "v10.28.0"
+ hash = "sha256-uKGZF1ChxE2aLeiU2V5YtzMqae+ksNI/UwZedOdpRmo="
[mod."github.com/leodido/go-urn"]
version = "v1.4.0"
hash = "sha256-Q6kplWkY37Tzy6GOme3Wut40jFK4Izun+ij/BJvcEu0="
[mod."golang.org/x/crypto"]
- version = "v0.41.0"
- hash = "sha256-o5Di0lsFmYnXl7a5MBTqmN9vXMCRpE9ay71C1Ar8jEY="
- [mod."golang.org/x/net"]
version = "v0.43.0"
- hash = "sha256-bf3iQFrsC8BoarVaS0uSspEFAcr1zHp1uziTtBpwV34="
+ hash = "sha256-Klv4v0G024WY2OWXsOEl4sKKI+SsUyqx++als1B6yn4="
[mod."golang.org/x/sys"]
- version = "v0.35.0"
- hash = "sha256-ZKM8pesQE6NAFZeKQ84oPn5JMhGr8g4TSwLYAsHMGSI="
+ version = "v0.37.0"
+ hash = "sha256-5aT0xP02sW1o9sfJHtWoGGNVYDdwb9FyiX/n6RAlzPo="
[mod."golang.org/x/text"]
- version = "v0.28.0"
- hash = "sha256-8UlJniGK+km4Hmrw6XMxELnExgrih7+z8tU26Cntmto="
+ version = "v0.30.0"
+ hash = "sha256-VPT1Y2zzgdk+Q3Gx8hdwKdxbVh0/Zn/HwDpILCW3ZNA="
[mod."gopkg.in/yaml.v3"]
version = "v3.0.1"
hash = "sha256-FqL9TKYJ0XkNwJFnq9j0VvJ5ZUU1RvH/52h/f5bkYAU="
diff --git a/src/vendor/github.com/gabriel-vasile/mimetype/CODE_OF_CONDUCT.md b/src/vendor/github.com/gabriel-vasile/mimetype/CODE_OF_CONDUCT.md
deleted file mode 100644
index 8479cd8..0000000
--- a/src/vendor/github.com/gabriel-vasile/mimetype/CODE_OF_CONDUCT.md
+++ /dev/null
@@ -1,76 +0,0 @@
-# Contributor Covenant Code of Conduct
-
-## Our Pledge
-
-In the interest of fostering an open and welcoming environment, we as
-contributors and maintainers pledge to making participation in our project and
-our community a harassment-free experience for everyone, regardless of age, body
-size, disability, ethnicity, sex characteristics, gender identity and expression,
-level of experience, education, socio-economic status, nationality, personal
-appearance, race, religion, or sexual identity and orientation.
-
-## Our Standards
-
-Examples of behavior that contributes to creating a positive environment
-include:
-
-* Using welcoming and inclusive language
-* Being respectful of differing viewpoints and experiences
-* Gracefully accepting constructive criticism
-* Focusing on what is best for the community
-* Showing empathy towards other community members
-
-Examples of unacceptable behavior by participants include:
-
-* The use of sexualized language or imagery and unwelcome sexual attention or
- advances
-* Trolling, insulting/derogatory comments, and personal or political attacks
-* Public or private harassment
-* Publishing others' private information, such as a physical or electronic
- address, without explicit permission
-* Other conduct which could reasonably be considered inappropriate in a
- professional setting
-
-## Our Responsibilities
-
-Project maintainers are responsible for clarifying the standards of acceptable
-behavior and are expected to take appropriate and fair corrective action in
-response to any instances of unacceptable behavior.
-
-Project maintainers have the right and responsibility to remove, edit, or
-reject comments, commits, code, wiki edits, issues, and other contributions
-that are not aligned to this Code of Conduct, or to ban temporarily or
-permanently any contributor for other behaviors that they deem inappropriate,
-threatening, offensive, or harmful.
-
-## Scope
-
-This Code of Conduct applies both within project spaces and in public spaces
-when an individual is representing the project or its community. Examples of
-representing a project or community include using an official project e-mail
-address, posting via an official social media account, or acting as an appointed
-representative at an online or offline event. Representation of a project may be
-further defined and clarified by project maintainers.
-
-## Enforcement
-
-Instances of abusive, harassing, or otherwise unacceptable behavior may be
-reported by contacting the project team at vasile.gabriel@email.com. All
-complaints will be reviewed and investigated and will result in a response that
-is deemed necessary and appropriate to the circumstances. The project team is
-obligated to maintain confidentiality with regard to the reporter of an incident.
-Further details of specific enforcement policies may be posted separately.
-
-Project maintainers who do not follow or enforce the Code of Conduct in good
-faith may face temporary or permanent repercussions as determined by other
-members of the project's leadership.
-
-## Attribution
-
-This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
-available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
-
-[homepage]: https://www.contributor-covenant.org
-
-For answers to common questions about this code of conduct, see
-https://www.contributor-covenant.org/faq
diff --git a/src/vendor/github.com/gabriel-vasile/mimetype/CONTRIBUTING.md b/src/vendor/github.com/gabriel-vasile/mimetype/CONTRIBUTING.md
deleted file mode 100644
index 56ae4e5..0000000
--- a/src/vendor/github.com/gabriel-vasile/mimetype/CONTRIBUTING.md
+++ /dev/null
@@ -1,12 +0,0 @@
-## Contribute
-Contributions to **mimetype** are welcome. If you find an issue and you consider
-contributing, you can use the [Github issues tracker](https://github.com/gabriel-vasile/mimetype/issues)
-in order to report it, or better yet, open a pull request.
-
-Code contributions must respect these rules:
- - code must be test covered
- - code must be formatted using gofmt tool
- - exported names must be documented
-
-**Important**: By submitting a pull request, you agree to allow the project
-owner to license your work under the same license as that used by the project.
diff --git a/src/vendor/github.com/gabriel-vasile/mimetype/README.md b/src/vendor/github.com/gabriel-vasile/mimetype/README.md
index aa88b4b..f28f56c 100644
--- a/src/vendor/github.com/gabriel-vasile/mimetype/README.md
+++ b/src/vendor/github.com/gabriel-vasile/mimetype/README.md
@@ -27,6 +27,7 @@
- possibility to [extend](https://pkg.go.dev/github.com/gabriel-vasile/mimetype#example-package-Extend) with other file formats
- common file formats are prioritized
- [text vs. binary files differentiation](https://pkg.go.dev/github.com/gabriel-vasile/mimetype#example-package-TextVsBinary)
+- no external dependencies
- safe for concurrent usage
## Install
@@ -45,8 +46,7 @@ fmt.Println(mtype.String(), mtype.Extension())
```
See the [runnable Go Playground examples](https://pkg.go.dev/github.com/gabriel-vasile/mimetype#pkg-overview).
-## Usage'
-Only use libraries like **mimetype** as a last resort. Content type detection
+Caution: only use libraries like **mimetype** as a last resort. Content type detection
using magic numbers is slow, inaccurate, and non-standard. Most of the times
protocols have methods for specifying such metadata; e.g., `Content-Type` header
in HTTP and SMTP.
@@ -67,6 +67,18 @@ mimetype.DetectFile("file.doc")
If increasing the limit does not help, please
[open an issue](https://github.com/gabriel-vasile/mimetype/issues/new?assignees=&labels=&template=mismatched-mime-type-detected.md&title=).
+## Tests
+In addition to unit tests,
+[mimetype_tests](https://github.com/gabriel-vasile/mimetype_tests) compares the
+library with the [Unix file utility](https://en.wikipedia.org/wiki/File_(command))
+for around 50 000 sample files. Check the latest comparison results
+[here](https://github.com/gabriel-vasile/mimetype_tests/actions).
+
+## Benchmarks
+Benchmarks for each file format are performed when a PR is open. The results can
+be seen on the [workflows page](https://github.com/gabriel-vasile/mimetype/actions/workflows/benchmark.yml).
+Performance improvements are welcome but correctness is prioritized.
+
## Structure
**mimetype** uses a hierarchical structure to keep the MIME type detection logic.
This reduces the number of calls needed for detecting the file type. The reason
@@ -84,19 +96,8 @@ or from a [file](https://pkg.go.dev/github.com/gabriel-vasile/mimetype#DetectFil
-## Performance
-Thanks to the hierarchical structure, searching for common formats first,
-and limiting itself to file headers, **mimetype** matches the performance of
-stdlib `http.DetectContentType` while outperforming the alternative package.
-
-```bash
- mimetype http.DetectContentType filetype
-BenchmarkMatchTar-24 250 ns/op 400 ns/op 3778 ns/op
-BenchmarkMatchZip-24 524 ns/op 351 ns/op 4884 ns/op
-BenchmarkMatchJpeg-24 103 ns/op 228 ns/op 839 ns/op
-BenchmarkMatchGif-24 139 ns/op 202 ns/op 751 ns/op
-BenchmarkMatchPng-24 165 ns/op 221 ns/op 1176 ns/op
-```
-
## Contributing
-See [CONTRIBUTING.md](CONTRIBUTING.md).
+Contributions are unexpected but welcome. When submitting a PR for detection of
+a new file format, please make sure to add a record to the list of testcases
+from [mimetype_test.go](mimetype_test.go). For complex files a record can be added
+in the [testdata](testdata) directory.
diff --git a/src/vendor/github.com/gabriel-vasile/mimetype/internal/charset/charset.go b/src/vendor/github.com/gabriel-vasile/mimetype/internal/charset/charset.go
index 0647f73..8c5a05e 100644
--- a/src/vendor/github.com/gabriel-vasile/mimetype/internal/charset/charset.go
+++ b/src/vendor/github.com/gabriel-vasile/mimetype/internal/charset/charset.go
@@ -2,11 +2,10 @@ package charset
import (
"bytes"
- "encoding/xml"
- "strings"
"unicode/utf8"
- "golang.org/x/net/html"
+ "github.com/gabriel-vasile/mimetype/internal/markup"
+ "github.com/gabriel-vasile/mimetype/internal/scan"
)
const (
@@ -141,20 +140,31 @@ func FromXML(content []byte) string {
}
return FromPlain(content)
}
-func fromXML(content []byte) string {
- content = trimLWS(content)
- dec := xml.NewDecoder(bytes.NewReader(content))
- rawT, err := dec.RawToken()
- if err != nil {
- return ""
- }
-
- t, ok := rawT.(xml.ProcInst)
- if !ok {
- return ""
+func fromXML(s scan.Bytes) string {
+ xml := []byte(" 0 && line[n-1] == '\r' {
+ return line[:n-1], false // drop \r at end of line
+ }
+
+ // This line is problematic. The logic from CountFields comes from
+ // encoding/csv.Reader which relies on mutating the input bytes.
+ // https://github.com/golang/go/blob/b3251514531123d7fd007682389bce7428d159a0/src/encoding/csv/reader.go#L275-L279
+ // To avoid mutating the input, we return cutShort. #680
+ if n >= 2 && line[n-2] == '\r' && line[n-1] == '\n' {
+ return line[:n-2], true
+ }
+ return line, false
+}
+
+// CountFields reads one CSV line and counts how many records that line contained.
+// hasMore reports whether there are more lines in the input.
+// collectIndexes makes CountFields return a list of indexes where CSV fields
+// start in the line. These indexes are used to test the correctness against the
+// encoding/csv parser.
+func (r *Parser) CountFields(collectIndexes bool) (fields int, fieldPos []int, hasMore bool) {
+ finished := false
+ var line scan.Bytes
+ cutShort := false
+ for {
+ line, cutShort = r.readLine()
+ if finished {
+ return 0, nil, false
+ }
+ finished = len(r.s) == 0 && len(line) == 0
+ if len(line) == lengthNL(line) {
+ line = nil
+ continue // Skip empty lines.
+ }
+ if len(line) > 0 && line[0] == r.comment {
+ line = nil
+ continue
+ }
+ break
+ }
+
+ indexes := []int{}
+ originalLine := line
+parseField:
+ for {
+ if len(line) == 0 || line[0] != '"' { // non-quoted string field
+ fields++
+ if collectIndexes {
+ indexes = append(indexes, len(originalLine)-len(line))
+ }
+ i := bytes.IndexByte(line, r.comma)
+ if i >= 0 {
+ line.Advance(i + 1) // 1 to get over ending comma
+ continue parseField
+ }
+ break parseField
+ } else { // Quoted string field.
+ if collectIndexes {
+ indexes = append(indexes, len(originalLine)-len(line))
+ }
+ line.Advance(1) // get over starting quote
+ for {
+ i := bytes.IndexByte(line, '"')
+ if i >= 0 {
+ line.Advance(i + 1) // 1 for ending quote
+ switch rn := line.Peek(); {
+ case rn == '"':
+ line.Advance(1)
+ case rn == r.comma:
+ line.Advance(1)
+ fields++
+ continue parseField
+ case lengthNL(line) == len(line):
+ fields++
+ break parseField
+ }
+ } else if len(line) > 0 || cutShort {
+ line, cutShort = r.readLine()
+ originalLine = line
+ } else {
+ fields++
+ break parseField
+ }
+ }
+ }
+ }
+
+ return fields, indexes, fields != 0
+}
+
+// lengthNL reports the number of bytes for the trailing \n.
+func lengthNL(b []byte) int {
+ if len(b) > 0 && b[len(b)-1] == '\n' {
+ return 1
+ }
+ return 0
+}
diff --git a/src/vendor/github.com/gabriel-vasile/mimetype/internal/json/parser.go b/src/vendor/github.com/gabriel-vasile/mimetype/internal/json/parser.go
index fd8dd52..4bc8617 100644
--- a/src/vendor/github.com/gabriel-vasile/mimetype/internal/json/parser.go
+++ b/src/vendor/github.com/gabriel-vasile/mimetype/internal/json/parser.go
@@ -258,7 +258,7 @@ out:
}
func (p *parserState) consumeArray(b []byte, qs []query, lvl int) (n int) {
- p.currPath = append(p.currPath, []byte{'['})
+ p.appendPath([]byte{'['}, qs)
if len(b) == 0 {
return 0
}
@@ -270,7 +270,7 @@ func (p *parserState) consumeArray(b []byte, qs []query, lvl int) (n int) {
}
if b[n] == ']' {
p.ib++
- p.currPath = p.currPath[:len(p.currPath)-1]
+ p.popLastPath(qs)
return n + 1
}
innerParsed := p.consumeAny(b[n:], qs, lvl)
@@ -305,6 +305,20 @@ func queryPathMatch(qs []query, path [][]byte) int {
return -1
}
+// appendPath will append a path fragment if queries is not empty.
+// If we don't need query functionality (just checking if a JSON is valid),
+// then we can skip keeping track of the path we're currently in.
+func (p *parserState) appendPath(path []byte, qs []query) {
+ if len(qs) != 0 {
+ p.currPath = append(p.currPath, path)
+ }
+}
+func (p *parserState) popLastPath(qs []query) {
+ if len(qs) != 0 {
+ p.currPath = p.currPath[:len(p.currPath)-1]
+ }
+}
+
func (p *parserState) consumeObject(b []byte, qs []query, lvl int) (n int) {
for n < len(b) {
n += p.consumeSpace(b[n:])
@@ -326,7 +340,7 @@ func (p *parserState) consumeObject(b []byte, qs []query, lvl int) (n int) {
if keyLen := p.consumeString(b[n:]); keyLen == 0 {
return 0
} else {
- p.currPath = append(p.currPath, b[n:n+keyLen-1])
+ p.appendPath(b[n:n+keyLen-1], qs)
if !p.querySatisfied {
queryMatched = queryPathMatch(qs, p.currPath)
}
@@ -368,12 +382,12 @@ func (p *parserState) consumeObject(b []byte, qs []query, lvl int) (n int) {
}
switch b[n] {
case ',':
- p.currPath = p.currPath[:len(p.currPath)-1]
+ p.popLastPath(qs)
n++
p.ib++
continue
case '}':
- p.currPath = p.currPath[:len(p.currPath)-1]
+ p.popLastPath(qs)
p.ib++
return n + 1
default:
@@ -388,6 +402,9 @@ func (p *parserState) consumeAny(b []byte, qs []query, lvl int) (n int) {
if p.maxRecursion != 0 && lvl > p.maxRecursion {
return 0
}
+ if len(qs) == 0 {
+ p.querySatisfied = true
+ }
n += p.consumeSpace(b)
if len(b[n:]) == 0 {
return 0
@@ -426,9 +443,6 @@ func (p *parserState) consumeAny(b []byte, qs []query, lvl int) (n int) {
if lvl == 0 {
p.firstToken = t
}
- if len(qs) == 0 {
- p.querySatisfied = true
- }
if rv <= 0 {
return n
}
diff --git a/src/vendor/github.com/gabriel-vasile/mimetype/internal/magic/document.go b/src/vendor/github.com/gabriel-vasile/mimetype/internal/magic/document.go
index b3b26d5..7f9308d 100644
--- a/src/vendor/github.com/gabriel-vasile/mimetype/internal/magic/document.go
+++ b/src/vendor/github.com/gabriel-vasile/mimetype/internal/magic/document.go
@@ -1,18 +1,11 @@
package magic
-import "bytes"
+import (
+ "bytes"
+ "encoding/binary"
+)
var (
- // Pdf matches a Portable Document Format file.
- // https://github.com/file/file/blob/11010cc805546a3e35597e67e1129a481aed40e8/magic/Magdir/pdf
- Pdf = prefix(
- // usual pdf signature
- []byte("%PDF-"),
- // new-line prefixed signature
- []byte("\012%PDF-"),
- // UTF-8 BOM prefixed signature
- []byte("\xef\xbb\xbf%PDF-"),
- )
// Fdf matches a Forms Data Format file.
Fdf = prefix([]byte("%FDF"))
// Mobi matches a Mobi file.
@@ -21,8 +14,18 @@ var (
Lit = prefix([]byte("ITOLITLS"))
)
+// PDF matches a Portable Document Format file.
+// The %PDF- header should be the first thing inside the file but many
+// implementations don't follow the rule. The PDF spec at Appendix H says the
+// signature can be prepended by anything.
+// https://bugs.astron.com/view.php?id=446
+func PDF(raw []byte, _ uint32) bool {
+ raw = raw[:min(len(raw), 1024)]
+ return bytes.Contains(raw, []byte("%PDF-"))
+}
+
// DjVu matches a DjVu file.
-func DjVu(raw []byte, limit uint32) bool {
+func DjVu(raw []byte, _ uint32) bool {
if len(raw) < 12 {
return false
}
@@ -36,7 +39,7 @@ func DjVu(raw []byte, limit uint32) bool {
}
// P7s matches an .p7s signature File (PEM, Base64).
-func P7s(raw []byte, limit uint32) bool {
+func P7s(raw []byte, _ uint32) bool {
// Check for PEM Encoding.
if bytes.HasPrefix(raw, []byte("-----BEGIN PKCS7")) {
return true
@@ -60,3 +63,21 @@ func P7s(raw []byte, limit uint32) bool {
return false
}
+
+// Lotus123 matches a Lotus 1-2-3 spreadsheet document.
+func Lotus123(raw []byte, _ uint32) bool {
+ if len(raw) <= 20 {
+ return false
+ }
+ version := binary.BigEndian.Uint32(raw)
+ if version == 0x00000200 {
+ return raw[6] != 0 && raw[7] == 0
+ }
+
+ return version == 0x00001a00 && raw[20] > 0 && raw[20] < 32
+}
+
+// CHM matches a Microsoft Compiled HTML Help file.
+func CHM(raw []byte, _ uint32) bool {
+ return bytes.HasPrefix(raw, []byte("ITSF\003\000\000\000\x60\000\000\000"))
+}
diff --git a/src/vendor/github.com/gabriel-vasile/mimetype/internal/magic/magic.go b/src/vendor/github.com/gabriel-vasile/mimetype/internal/magic/magic.go
index a34c609..5fe435b 100644
--- a/src/vendor/github.com/gabriel-vasile/mimetype/internal/magic/magic.go
+++ b/src/vendor/github.com/gabriel-vasile/mimetype/internal/magic/magic.go
@@ -4,6 +4,8 @@ package magic
import (
"bytes"
"fmt"
+
+ "github.com/gabriel-vasile/mimetype/internal/scan"
)
type (
@@ -74,12 +76,13 @@ func ciCheck(sig, raw []byte) bool {
// matches the raw input.
func xml(sigs ...xmlSig) Detector {
return func(raw []byte, limit uint32) bool {
- raw = trimLWS(raw)
- if len(raw) == 0 {
+ b := scan.Bytes(raw)
+ b.TrimLWS()
+ if len(b) == 0 {
return false
}
for _, s := range sigs {
- if xmlCheck(s, raw) {
+ if xmlCheck(s, b) {
return true
}
}
@@ -104,19 +107,19 @@ func xmlCheck(sig xmlSig, raw []byte) bool {
// matches the raw input.
func markup(sigs ...[]byte) Detector {
return func(raw []byte, limit uint32) bool {
- if bytes.HasPrefix(raw, []byte{0xEF, 0xBB, 0xBF}) {
+ b := scan.Bytes(raw)
+ if bytes.HasPrefix(b, []byte{0xEF, 0xBB, 0xBF}) {
// We skip the UTF-8 BOM if present to ensure we correctly
// process any leading whitespace. The presence of the BOM
// is taken into account during charset detection in charset.go.
- raw = trimLWS(raw[3:])
- } else {
- raw = trimLWS(raw)
+ b.Advance(3)
}
- if len(raw) == 0 {
+ b.TrimLWS()
+ if len(b) == 0 {
return false
}
for _, s := range sigs {
- if markupCheck(s, raw) {
+ if markupCheck(s, b) {
return true
}
}
@@ -139,7 +142,7 @@ func markupCheck(sig, raw []byte) bool {
}
}
// Next byte must be space or right angle bracket.
- if db := raw[len(sig)]; db != ' ' && db != '>' {
+ if db := raw[len(sig)]; !scan.ByteIsWS(db) && db != '>' {
return false
}
@@ -183,8 +186,10 @@ func newXMLSig(localName, xmlns string) xmlSig {
// /usr/bin/env is the interpreter, php is the first and only argument.
func shebang(sigs ...[]byte) Detector {
return func(raw []byte, limit uint32) bool {
+ b := scan.Bytes(raw)
+ line := b.Line()
for _, s := range sigs {
- if shebangCheck(s, firstLine(raw)) {
+ if shebangCheck(s, line) {
return true
}
}
@@ -192,7 +197,7 @@ func shebang(sigs ...[]byte) Detector {
}
}
-func shebangCheck(sig, raw []byte) bool {
+func shebangCheck(sig []byte, raw scan.Bytes) bool {
if len(raw) < len(sig)+2 {
return false
}
@@ -200,52 +205,8 @@ func shebangCheck(sig, raw []byte) bool {
return false
}
- return bytes.Equal(trimLWS(trimRWS(raw[2:])), sig)
-}
-
-// trimLWS trims whitespace from beginning of the input.
-func trimLWS(in []byte) []byte {
- firstNonWS := 0
- for ; firstNonWS < len(in) && isWS(in[firstNonWS]); firstNonWS++ {
- }
-
- return in[firstNonWS:]
-}
-
-// trimRWS trims whitespace from the end of the input.
-func trimRWS(in []byte) []byte {
- lastNonWS := len(in) - 1
- for ; lastNonWS > 0 && isWS(in[lastNonWS]); lastNonWS-- {
- }
-
- return in[:lastNonWS+1]
-}
-
-func firstLine(in []byte) []byte {
- lineEnd := 0
- for ; lineEnd < len(in) && in[lineEnd] != '\n'; lineEnd++ {
- }
-
- return in[:lineEnd]
-}
-
-func isWS(b byte) bool {
- return b == '\t' || b == '\n' || b == '\x0c' || b == '\r' || b == ' '
-}
-
-func min(a, b int) int {
- if a < b {
- return a
- }
- return b
-}
-
-type readBuf []byte
-
-func (b *readBuf) advance(n int) bool {
- if n < 0 || len(*b) < n {
- return false
- }
- *b = (*b)[n:]
- return true
+ raw.Advance(2) // skip #! we checked above
+ raw.TrimLWS()
+ raw.TrimRWS()
+ return bytes.Equal(raw, sig)
}
diff --git a/src/vendor/github.com/gabriel-vasile/mimetype/internal/magic/ms_office.go b/src/vendor/github.com/gabriel-vasile/mimetype/internal/magic/ms_office.go
index 7d60e22..c912823 100644
--- a/src/vendor/github.com/gabriel-vasile/mimetype/internal/magic/ms_office.go
+++ b/src/vendor/github.com/gabriel-vasile/mimetype/internal/magic/ms_office.go
@@ -7,17 +7,34 @@ import (
// Xlsx matches a Microsoft Excel 2007 file.
func Xlsx(raw []byte, limit uint32) bool {
- return zipContains(raw, []byte("xl/"), true)
+ return msoxml(raw, zipEntries{{
+ name: []byte("xl/"),
+ dir: true,
+ }}, 100)
}
// Docx matches a Microsoft Word 2007 file.
func Docx(raw []byte, limit uint32) bool {
- return zipContains(raw, []byte("word/"), true)
+ return msoxml(raw, zipEntries{{
+ name: []byte("word/"),
+ dir: true,
+ }}, 100)
}
// Pptx matches a Microsoft PowerPoint 2007 file.
func Pptx(raw []byte, limit uint32) bool {
- return zipContains(raw, []byte("ppt/"), true)
+ return msoxml(raw, zipEntries{{
+ name: []byte("ppt/"),
+ dir: true,
+ }}, 100)
+}
+
+// Visio matches a Microsoft Visio 2013+ file.
+func Visio(raw []byte, limit uint32) bool {
+ return msoxml(raw, zipEntries{{
+ name: []byte("visio/"),
+ dir: true,
+ }}, 100)
}
// Ole matches an Open Linking and Embedding file.
@@ -157,6 +174,14 @@ func Msi(raw []byte, limit uint32) bool {
})
}
+// One matches a Microsoft OneNote file.
+func One(raw []byte, limit uint32) bool {
+ return bytes.HasPrefix(raw, []byte{
+ 0xe4, 0x52, 0x5c, 0x7b, 0x8c, 0xd8, 0xa7, 0x4d,
+ 0xae, 0xb1, 0x53, 0x78, 0xd0, 0x29, 0x96, 0xd3,
+ })
+}
+
// Helper to match by a specific CLSID of a compound file.
//
// http://fileformats.archiveteam.org/wiki/Microsoft_Compound_File
diff --git a/src/vendor/github.com/gabriel-vasile/mimetype/internal/magic/netpbm.go b/src/vendor/github.com/gabriel-vasile/mimetype/internal/magic/netpbm.go
new file mode 100644
index 0000000..4baa257
--- /dev/null
+++ b/src/vendor/github.com/gabriel-vasile/mimetype/internal/magic/netpbm.go
@@ -0,0 +1,111 @@
+package magic
+
+import (
+ "bytes"
+ "strconv"
+
+ "github.com/gabriel-vasile/mimetype/internal/scan"
+)
+
+// NetPBM matches a Netpbm Portable BitMap ASCII/Binary file.
+//
+// See: https://en.wikipedia.org/wiki/Netpbm
+func NetPBM(raw []byte, _ uint32) bool {
+ return netp(raw, "P1\n", "P4\n")
+}
+
+// NetPGM matches a Netpbm Portable GrayMap ASCII/Binary file.
+//
+// See: https://en.wikipedia.org/wiki/Netpbm
+func NetPGM(raw []byte, _ uint32) bool {
+ return netp(raw, "P2\n", "P5\n")
+}
+
+// NetPPM matches a Netpbm Portable PixMap ASCII/Binary file.
+//
+// See: https://en.wikipedia.org/wiki/Netpbm
+func NetPPM(raw []byte, _ uint32) bool {
+ return netp(raw, "P3\n", "P6\n")
+}
+
+// NetPAM matches a Netpbm Portable Arbitrary Map file.
+//
+// See: https://en.wikipedia.org/wiki/Netpbm
+func NetPAM(raw []byte, _ uint32) bool {
+ if !bytes.HasPrefix(raw, []byte("P7\n")) {
+ return false
+ }
+ w, h, d, m, e := false, false, false, false, false
+ s := scan.Bytes(raw)
+ var l scan.Bytes
+ // Read line by line.
+ for i := 0; i < 128; i++ {
+ l = s.Line()
+ // If the line is empty or a comment, skip.
+ if len(l) == 0 || l.Peek() == '#' {
+ if len(s) == 0 {
+ return false
+ }
+ continue
+ } else if bytes.HasPrefix(l, []byte("TUPLTYPE")) {
+ continue
+ } else if bytes.HasPrefix(l, []byte("WIDTH ")) {
+ w = true
+ } else if bytes.HasPrefix(l, []byte("HEIGHT ")) {
+ h = true
+ } else if bytes.HasPrefix(l, []byte("DEPTH ")) {
+ d = true
+ } else if bytes.HasPrefix(l, []byte("MAXVAL ")) {
+ m = true
+ } else if bytes.HasPrefix(l, []byte("ENDHDR")) {
+ e = true
+ }
+ // When we reached header, return true if we collected all four required headers.
+ // WIDTH, HEIGHT, DEPTH and MAXVAL.
+ if e {
+ return w && h && d && m
+ }
+ }
+ return false
+}
+
+func netp(s scan.Bytes, prefixes ...string) bool {
+ foundPrefix := ""
+ for _, p := range prefixes {
+ if bytes.HasPrefix(s, []byte(p)) {
+ foundPrefix = p
+ }
+ }
+ if foundPrefix == "" {
+ return false
+ }
+ s.Advance(len(foundPrefix)) // jump over P1, P2, P3, etc.
+
+ var l scan.Bytes
+ // Read line by line.
+ for i := 0; i < 128; i++ {
+ l = s.Line()
+ // If the line is a comment, skip.
+ if l.Peek() == '#' {
+ continue
+ }
+ // If line has leading whitespace, then skip over whitespace.
+ for scan.ByteIsWS(l.Peek()) {
+ l.Advance(1)
+ }
+ if len(s) == 0 || len(l) > 0 {
+ break
+ }
+ }
+
+ // At this point l should be the two integers denoting the size of the matrix.
+ width := l.PopUntil(scan.ASCIISpaces...)
+ for scan.ByteIsWS(l.Peek()) {
+ l.Advance(1)
+ }
+ height := l.PopUntil(scan.ASCIISpaces...)
+
+ w, errw := strconv.ParseInt(string(width), 10, 64)
+ h, errh := strconv.ParseInt(string(height), 10, 64)
+ return errw == nil && errh == nil && w > 0 && h > 0
+}
diff --git a/src/vendor/github.com/gabriel-vasile/mimetype/internal/magic/text.go b/src/vendor/github.com/gabriel-vasile/mimetype/internal/magic/text.go
index 8178e47..1841ee8 100644
--- a/src/vendor/github.com/gabriel-vasile/mimetype/internal/magic/text.go
+++ b/src/vendor/github.com/gabriel-vasile/mimetype/internal/magic/text.go
@@ -6,6 +6,8 @@ import (
"github.com/gabriel-vasile/mimetype/internal/charset"
"github.com/gabriel-vasile/mimetype/internal/json"
+ mkup "github.com/gabriel-vasile/mimetype/internal/markup"
+ "github.com/gabriel-vasile/mimetype/internal/scan"
)
var (
@@ -27,6 +29,7 @@ var (
[]byte("
+//
+func svgWithoutXMLDeclaration(s scan.Bytes) bool {
+ for scan.ByteIsWS(s.Peek()) {
+ s.Advance(1)
+ }
+ for mkup.SkipAComment(&s) {
+ }
+ if !bytes.HasPrefix(s, []byte("