github.com/opentofu/opentofu@v1.7.1/internal/states/statefile/version0.go (about) 1 // Copyright (c) The OpenTofu Authors 2 // SPDX-License-Identifier: MPL-2.0 3 // Copyright (c) 2023 HashiCorp, Inc. 4 // SPDX-License-Identifier: MPL-2.0 5 6 package statefile 7 8 // looksLikeVersion0 sniffs for the signature indicating a version 0 state 9 // file. 10 // 11 // Version 0 was the number retroactively assigned to OpenTofu's initial 12 // (unversioned) binary state file format, which was later superseded by the 13 // version 1 format in JSON. 14 // 15 // Version 0 is no longer supported, so this is used only to detect it and 16 // return a nice error to the user. 17 func looksLikeVersion0(src []byte) bool { 18 // Version 0 files begin with the magic prefix "tfstate". 19 const magic = "tfstate" 20 if len(src) < len(magic) { 21 // Not even long enough to have the magic prefix 22 return false 23 } 24 if string(src[0:len(magic)]) == magic { 25 return true 26 } 27 return false 28 }