{"record":{"id":"26fb782a99af7d51","repo":"hyperledger/fabric","slug":"dir-s-not-empty","errorCode":null,"errorMessage":"dir %s not empty","messagePattern":"dir (.+?) not empty","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"common/ledger/blkstorage/blockfile_mgr.go","lineNumber":185,"sourceCode":"\t}\n\tmgr.bcInfo.Store(bcInfo)\n\treturn mgr, nil\n}\n\nfunc bootstrapFromSnapshottedTxIDs(\n\tledgerID string,\n\tsnapshotDir string,\n\tsnapshotInfo *SnapshotInfo,\n\tconf *Conf,\n\tindexStore *leveldbhelper.DBHandle,\n) error {\n\trootDir := conf.getLedgerBlockDir(ledgerID)\n\tisEmpty, err := fileutil.CreateDirIfMissing(rootDir)\n\tif err != nil {\n\t\treturn err\n\t}\n\tif !isEmpty {\n\t\treturn errors.Errorf(\"dir %s not empty\", rootDir)\n\t}\n\n\tbsi := &BootstrappingSnapshotInfo{\n\t\tLastBlockNum:      snapshotInfo.LastBlockNum,\n\t\tLastBlockHash:     snapshotInfo.LastBlockHash,\n\t\tPreviousBlockHash: snapshotInfo.PreviousBlockHash,\n\t}\n\n\tbsiBytes, err := proto.Marshal(bsi)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tif err = fileutil.CreateAndSyncFileAtomically(\n\t\trootDir,\n\t\tbootstrappingSnapshotInfoTempFile,\n\t\tbootstrappingSnapshotInfoFile,\n\t\tbsiBytes,","sourceCodeStart":167,"sourceCodeEnd":203,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/common/ledger/blkstorage/blockfile_mgr.go#L167-L203","documentation":"bootstrapFromSnapshottedTxIDs imports a snapshot into a fresh ledger directory, but only if the ledger's block directory is empty (CreateDirIfMissing returns isEmpty). If any files already exist under the ledger's blocks dir, it refuses with 'dir %s not empty' rather than mixing snapshot data with existing blocks.","triggerScenarios":"Calling ImportFromSnapshot (bootstrapFromSnapshottedTxIDs) for a ledgerID whose block directory (ledgersData/chains/chains/<ledgerID>/blocks) already contains files — e.g., the ledger previously existed, or a prior snapshot import partially completed leaving metadata behind.","commonSituations":"Re-running snapshot import after a failed attempt; importing into a peer that already has the channel/ledger; leftover files from a ledger reset that only cleared some subdirectories; wrong ledgerDataPath pointing at an existing peer's data.","solutions":["Ensure the peer is fresh/reset for that ledger: stop the peer and remove ledgersData/chains/chains/<ledgerID> (or run peer node reset) before importing","Retry the import — a prior partial import must be cleaned first since it is not resumable","Verify you are importing on a peer that is not already joined to the channel","Check ledgerDataPath config points to the intended (empty) data root"],"exampleFix":"// before: ImportFromSnapshot fails with 'dir ... not empty'\nsystemctl stop peer\nrm -rf /var/hyperledger/production/ledgersData/chains/chains/mychannel\nsystemctl start peer\n# after: import succeeds into empty dir\npeer node import-snapshot ...","handlingStrategy":"validation","validationCode":"// check the target ledger blocks dir is empty before ImportFromSnapshot\nfunc dirIsEmpty(p string) (bool, error) {\n\tif _, err := os.Stat(p); os.IsNotExist(err) { return true, nil }\n\tf, err := os.Open(p)\n\tif err != nil { return false, err }\n\tdefer f.Close()\n\tnames, err := f.Readdirnames(-1)\n\tif err != nil { return false, err }\n\treturn len(names) == 0, nil\n}","typeGuard":null,"tryCatchPattern":"if err := blkstorage.ImportFromSnapshot(...); err != nil {\n    if strings.Contains(err.Error(), \"not empty\") {\n        // recover: wipe the ledger dir (or run 'peer node reset') and retry import\n    }\n    return err\n}","preventionTips":["Only import snapshots into a freshly reset peer ('peer node reset' first)","Never re-run a failed snapshot import without cleaning the ledger directory first","Confirm the peer is not already joined to the channel before importing","Point ledgerDataPath at a dedicated, empty data root for snapshot imports"],"tags":["hyperledger-fabric","snapshot","ledger","import","directory-not-empty"],"backgroundTag":"snapshot-import-dir-not-empty","analyzedSha":"2736b63f8fd5932511d56fe68b7039d15977f7f6","analyzedAt":"2026-09-04T08:52:36.465Z","contentChangedAt":"2026-09-04T08:52:36.465Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}