github.com/terramate-io/tf@v0.0.0-20230830114523-fce866b4dfcd/states/statefile/version0.go (about)

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