{"record":{"id":"80a3085c357606e3","repo":"hashicorp/vagrant","slug":"the-specified-file-filename-to-save-the-packa","errorCode":null,"errorMessage":"The specified file '%{filename}' to save the package as already exists. Please remove this file or specify a different file name for outputting.","messagePattern":"The specified file '%(.+?)' to save the package as already exists\\. Please remove this file or specify a different file name for outputting\\.","errorType":"exception","errorClass":"Vagrant::Errors::PackageOutputExists","httpStatus":null,"severity":"error","filePath":"lib/vagrant/action/general/package.rb","lineNumber":45,"sourceCode":"        # Perform sanity validations that the provided output filepath is sane.\n        # In particular, this function validates:\n        #\n        #   - The output path is a regular file (not a directory or symlink)\n        #   - No file currently exists at the given path\n        #   - A directory of package files was actually provided (internal)\n        #\n        # @param [String] output path to the output file\n        # @param [String] directory path to a directory containing the files\n        def self.validate!(output, directory)\n          filename = File.basename(output.to_s)\n          output   = fullpath(output)\n\n          if File.directory?(output)\n            raise Vagrant::Errors::PackageOutputDirectory\n          end\n\n          if File.exist?(output)\n            raise Vagrant::Errors::PackageOutputExists, filename: filename\n          end\n\n          if !Vagrant::Util::Presence.present?(directory) || !File.directory?(directory)\n            raise Vagrant::Errors::PackageRequiresDirectory\n          end\n        end\n\n        # Calculate the full path of the given path, relative to the current\n        # working directory (where the command was run).\n        #\n        # @param [String] output the relative path\n        def self.fullpath(output)\n          File.expand_path(output, Dir.pwd)\n        end\n\n        # The path to the final output file.\n        # @return [String]\n        attr_reader :fullpath","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/hashicorp/vagrant/blob/35f3160f4ad6edc3a9f3aa9570adfc1a4d73aaa5/lib/vagrant/action/general/package.rb#L27-L63","documentation":"Package.validate! refuses to overwrite existing output: after expanding the --output path (default package.box in the cwd), if a regular file already exists there, PackageOutputExists is raised with its basename. This is a deliberate guard so repeated packaging runs don't silently clobber previous .box artifacts.","triggerScenarios":"Running `vagrant package [--output X]` when X (or ./package.box) already exists as a file — running package twice, CI re-runs without workspace cleanup, or a stale artifact from an earlier attempt (lib/vagrant/action/general/package.rb:44-46).","commonSituations":" scripted packaging loops that use a fixed output name; CI pipelines re-running on the same workspace; iterating on a box locally and forgetting the previous file.","solutions":["Delete or move the existing file: `rm -f package.box` (or your --output path), then re-run `vagrant package`.","Or write each run to a fresh name: `vagrant package --output \"mybox-$(date +%Y%m%d-%H%M%S).box\"`.","In CI, add a cleanup step before the package step."],"exampleFix":"# before\nvagrant package --output myapp.box   # second run => PackageOutputExists\n\n# after\nrm -f myapp.box && vagrant package --output myapp.box\n# or versioned outputs:\nvagrant package --output \"myapp-$(date +%Y%m%d-%H%M%S).box\"","handlingStrategy":"validation","validationCode":"# Shell: package only when the output path is clear\nout=\"${PACKAGE_OUT:-package.box}\"\nif [ -e \"$out\" ] && [ ! -d \"$out\" ]; then rm -f \"$out\"; fi\nvagrant package --output \"$out\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use timestamped --output names in scripts so reruns never collide.","Add `rm -f package.box` (or a workspace-cleanup step) before the package step in CI.","Never point --output at a path another process still consumes."],"tags":["vagrant","package","packaging","file-exists"],"backgroundTag":"file-already-exists","analyzedSha":"35f3160f4ad6edc3a9f3aa9570adfc1a4d73aaa5","analyzedAt":"2026-08-21T13:34:32.514Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}