Skip to content

sam build --build-dir . will nuke current working directory #1157

@m1keil

Description

@m1keil

Description

Executing sam build --build-dir . will fail and result in removal of all files in current working directory.

Steps to reproduce

sam init -r python3.7
cd sam-app
sam build --build-dir .

Observed result

$ sam build --debug --build-dir .
2019-04-30 02:18:11 Using SAM Template at /private/tmp/sam-app/template.yaml
2019-04-30 02:18:11 Changing event name from creating-client-class.iot-data to creating-client-class.iot-data-plane
2019-04-30 02:18:11 Changing event name from before-call.apigateway to before-call.api-gateway
2019-04-30 02:18:11 Changing event name from request-created.machinelearning.Predict to request-created.machine-learning.Predict
2019-04-30 02:18:11 Changing event name from before-parameter-build.autoscaling.CreateLaunchConfiguration to before-parameter-build.auto-scaling.CreateLaunchConfiguration
2019-04-30 02:18:11 Changing event name from before-parameter-build.route53 to before-parameter-build.route-53
2019-04-30 02:18:11 Changing event name from request-created.cloudsearchdomain.Search to request-created.cloudsearch-domain.Search
2019-04-30 02:18:11 Changing event name from docs.*.autoscaling.CreateLaunchConfiguration.complete-section to docs.*.auto-scaling.CreateLaunchConfiguration.complete-section
2019-04-30 02:18:11 Changing event name from before-parameter-build.logs.CreateExportTask to before-parameter-build.cloudwatch-logs.CreateExportTask
2019-04-30 02:18:11 Changing event name from docs.*.logs.CreateExportTask.complete-section to docs.*.cloudwatch-logs.CreateExportTask.complete-section
2019-04-30 02:18:11 Changing event name from before-parameter-build.cloudsearchdomain.Search to before-parameter-build.cloudsearch-domain.Search
2019-04-30 02:18:11 Changing event name from docs.*.cloudsearchdomain.Search.complete-section to docs.*.cloudsearch-domain.Search.complete-section
2019-04-30 02:18:11 Changing event name from creating-client-class.iot-data to creating-client-class.iot-data-plane
2019-04-30 02:18:11 Changing event name from before-call.apigateway to before-call.api-gateway
2019-04-30 02:18:11 Changing event name from request-created.machinelearning.Predict to request-created.machine-learning.Predict
2019-04-30 02:18:11 Changing event name from before-parameter-build.autoscaling.CreateLaunchConfiguration to before-parameter-build.auto-scaling.CreateLaunchConfiguration
2019-04-30 02:18:11 Changing event name from before-parameter-build.route53 to before-parameter-build.route-53
2019-04-30 02:18:11 Changing event name from request-created.cloudsearchdomain.Search to request-created.cloudsearch-domain.Search
2019-04-30 02:18:11 Changing event name from docs.*.autoscaling.CreateLaunchConfiguration.complete-section to docs.*.auto-scaling.CreateLaunchConfiguration.complete-section
2019-04-30 02:18:11 Changing event name from before-parameter-build.logs.CreateExportTask to before-parameter-build.cloudwatch-logs.CreateExportTask
2019-04-30 02:18:11 Changing event name from docs.*.logs.CreateExportTask.complete-section to docs.*.cloudwatch-logs.CreateExportTask.complete-section
2019-04-30 02:18:11 Changing event name from before-parameter-build.cloudsearchdomain.Search to before-parameter-build.cloudsearch-domain.Search
2019-04-30 02:18:11 Changing event name from docs.*.cloudsearchdomain.Search.complete-section to docs.*.cloudsearch-domain.Search.complete-section
2019-04-30 02:18:11 'build' command is called
2019-04-30 02:18:11 No Parameters detected in the template
2019-04-30 02:18:11 2 resources found in the template
2019-04-30 02:18:11 Found Serverless function with name='HelloWorldFunction' and CodeUri='hello_world/'
Traceback (most recent call last):
  File "/usr/local/bin/sam", line 11, in <module>
    load_entry_point('aws-sam-cli==0.15.0', 'console_scripts', 'sam')()
  File "/usr/local/Cellar/aws-sam-cli/0.15.0/libexec/lib/python3.7/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/Cellar/aws-sam-cli/0.15.0/libexec/lib/python3.7/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/usr/local/Cellar/aws-sam-cli/0.15.0/libexec/lib/python3.7/site-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/Cellar/aws-sam-cli/0.15.0/libexec/lib/python3.7/site-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/Cellar/aws-sam-cli/0.15.0/libexec/lib/python3.7/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/Cellar/aws-sam-cli/0.15.0/libexec/lib/python3.7/site-packages/click/decorators.py", line 64, in new_func
    return ctx.invoke(f, obj, *args[1:], **kwargs)
  File "/usr/local/Cellar/aws-sam-cli/0.15.0/libexec/lib/python3.7/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/Cellar/aws-sam-cli/0.15.0/libexec/lib/python3.7/site-packages/samcli/commands/build/command.py", line 100, in cli
    skip_pull_image, parameter_overrides, mode)  # pragma: no cover
  File "/usr/local/Cellar/aws-sam-cli/0.15.0/libexec/lib/python3.7/site-packages/samcli/commands/build/command.py", line 131, in do_cli
    mode=mode) as ctx:
  File "/usr/local/Cellar/aws-sam-cli/0.15.0/libexec/lib/python3.7/site-packages/samcli/commands/build/build_context.py", line 65, in __enter__
    self._build_dir = self._setup_build_dir(self._build_dir, self._clean)
  File "/usr/local/Cellar/aws-sam-cli/0.15.0/libexec/lib/python3.7/site-packages/samcli/commands/build/build_context.py", line 82, in _setup_build_dir
    shutil.rmtree(build_dir)
  File "/usr/local/Cellar/aws-sam-cli/0.15.0/libexec/lib/python3.7/shutil.py", line 495, in rmtree
    onerror(os.rmdir, path, sys.exc_info())
  File "/usr/local/Cellar/aws-sam-cli/0.15.0/libexec/lib/python3.7/shutil.py", line 493, in rmtree
    os.rmdir(path)
OSError: [Errno 22] Invalid argument: '.'

Expected result

It should either:
a) fail cleanly
b) create a .aws-sam directory inside the build-dir which it can remove without worry in case of failure.

Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

  1. OS: macOS 10.14.4 (python via brew)
  2. SAM CLI, version 0.15.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions