code: func (s *Filesystem) createStateFiles() error {
  	log.Printf("[TRACE] statemgr.Filesystem: preparing to manage state snapshots at %s", s.path)
  
  	// This could race, but we only use it to clean up empty files
  	if _, err := os.Stat(s.path); os.IsNotExist(err) {
  		s.created = true
  	}
  
  	// Create all the directories
  	if err := os.MkdirAll(filepath.Dir(s.path), 0755); err != nil {
  		return err
  	}
  
  	f, err := os.OpenFile(s.path, os.O_RDWR|os.O_CREATE, 0666)
  	if err != nil {
  		return err
  	}
  
  	s.stateFileOut = f
  
  	// If the file already existed with content then that'll be the content
  	// of our backup file if we write a change later.
  	s.backupFile, err = statefile.Read(s.stateFileOut)
  	if err != nil {
  		if err != statefile.ErrNoState {
  			return err
  		}
  		log.Printf("[TRACE] statemgr.Filesystem: no previously-stored snapshot exists")
  	} else {
  		log.Printf("[TRACE] statemgr.Filesystem: existing snapshot has lineage %q serial %d", s.backupFile.Lineage, s.backupFile.Serial)
  	}
  
  	// Refresh now, to load in the snapshot if the file already existed
  	return nil
  }
docs: // Open the state file, creating the directories and file as needed.