Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: change permissions and remove files on rmtree #1694

Merged
merged 2 commits into from
Jan 3, 2020

Conversation

sriram-mv
Copy link
Contributor

@sriram-mv sriram-mv commented Dec 26, 2019

fix: change permissions and remove files on rmtree

Why is this change necessary?

  • sam init clones from a git repository called aws-sam-cli-app-templates, but when attempting to reclone, removal of the old directory becomes problematic due to the read-only nature of the .git files that get downloaded and results in a traceback.

How does it address the issue?

  • If a given file is not able to be deleted due to permission issues, write permissions are added to the file in question and deleted.

What side effects does this change have?

  • None, the previous side-effects of leaving behind .git objects will be addressed.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@sriram-mv sriram-mv merged commit 741d22b into aws:develop Jan 3, 2020
@rajendragosavi
Copy link

I see the issue still persists. I had to follow @sriram-mv instructions manually. I am using sam 0.52.0 and I still see this issue.

@kannan-kiwitech
Copy link

I'm getting the same issue in recent version

SAM CLI, version 1.46.0 Windows 11

2022-04-15 14:44:58,488 | Cloning from https://github.com/aws/aws-sam-cli-app-templates (process may take a moment) 2022-04-15 14:45:02,933 | Removing old repo at C:\Users\xxx\AppData\Roaming\AWS SAM\aws-sam-cli-app-templates 2022-04-15 14:45:03,293 | Copying from C:\Users\xxx\AppData\Local\Temp\tmp_6asyom5\aws-sam-cli-app-templates to C:\Users\xxx\AppData\Roaming\AWS SAM\aws-sam-cli-app-templates 2022-04-15 14:45:07,097 | rmtree failed in <built-in function unlink> for C:\Users\xxx\AppData\Local\Temp\tmp_6asyom5\aws-sam-cli-app-templates\dotnetcore3.1\cookiecutter-aws-sam-quick-start-cloudwatch-events-dotnet\{{cookiecutter.project_name}}\test\{{cookiecutter.project_name}}.Tests\{{cookiecutter.project_name}}.Tests.csproj, details: (<class 'FileNotFoundError'>, FileNotFoundError(2, 'The system cannot find the path specified'), <traceback object at 0x000001B0E94FE380>) 2022-04-15 14:45:07,097 | rmtree failed in <built-in function rmdir> for C:\Users\xxx\AppData\Local\Temp\tmp_6asyom5\aws-sam-cli-app-templates\dotnetcore3.1\cookiecutter-aws-sam-quick-start-cloudwatch-events-dotnet\{{cookiecutter.project_name}}\test\{{cookiecutter.project_name}}.Tests, details: (<class 'OSError'>, OSError(41, 'The directory is not empty'), <traceback object at 0x000001B0E94FE380>) 2022-04-15 14:45:07,098 | rmtree failed in <built-in function rmdir> for C:\Users\xxx\AppData\Local\Temp\tmp_6asyom5\aws-sam-cli-app-templates\dotnetcore3.1\cookiecutter-aws-sam-quick-start-cloudwatch-events-dotnet\{{cookiecutter.project_name}}\test, details: (<class 'OSError'>, OSError(41, 'The directory is not empty'), <traceback object at 0x000001B0E94FE300>) 2022-04-15 14:45:07,098 | rmtree failed in <built-in function rmdir> for C:\Users\xxx\AppData\Local\Temp\tmp_6asyom5\aws-sam-cli-app-templates\dotnetcore3.1\cookiecutter-aws-sam-quick-start-cloudwatch-events-dotnet\{{cookiecutter.project_name}}, details: (<class 'OSError'>, OSError(41, 'The directory is not empty'), <traceback object at 0x000001B0E94FE2C0>) 2022-04-15 14:45:07,098 | rmtree failed in <built-in function rmdir> for C:\Users\xxx\AppData\Local\Temp\tmp_6asyom5\aws-sam-cli-app-templates\dotnetcore3.1\cookiecutter-aws-sam-quick-start-cloudwatch-events-dotnet, details: (<class 'OSError'>, OSError(41, 'The directory is not empty'), <traceback object at 0x000001B0E94FE280>) 2022-04-15 14:45:07,114 | rmtree failed in <built-in function rmdir> for C:\Users\xxx\AppData\Local\Temp\tmp_6asyom5\aws-sam-cli-app-templates\dotnetcore3.1, details: (<class 'OSError'>, OSError(41, 'The directory is not empty'), <traceback object at 0x000001B0E94EDF40>) 2022-04-15 14:45:07,374 | rmtree failed in <built-in function rmdir> for C:\Users\xxx\AppData\Local\Temp\tmp_6asyom5\aws-sam-cli-app-templates, details: (<class 'OSError'>, OSError(41, 'The directory is not empty'), <traceback object at 0x000001B0E94EDFC0>) 2022-04-15 14:45:07,374 | rmtree failed in <built-in function rmdir> for C:\Users\xxx\AppData\Local\Temp\tmp_6asyom5, details: (<class 'OSError'>, OSError(41, 'The directory is not empty'), <traceback object at 0x000001B0E94E96C0>) 2022-04-15 14:45:07,374 | Template is not provided in context, skip adding project type metric 2022-04-15 14:45:07,374 | Sending Telemetry: {'metrics': [{'commandRun': {'requestId': '5da8e467-86df-452a-97c9-a3e731b4bb19', 'installationId': '6faffe73-4122-48c5-99f4-d776ccc56cff', 'sessionId': 'c0934b02-bd88-459e-aae4-6332a4893a22', 'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.8.8', 'samcliVersion': '1.46.0', 'awsProfileProvided': False, 'debugFlagProvided': True, 'region': '', 'commandName': 'sam init', 'duration': 20652, 'exitReason': 'AppTemplateUpdateException', 'exitCode': 1}}]} 2022-04-15 14:45:08,429 | HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out. (read timeout=0.1) Error: Unstable state when updating repo. Check that you have permissions to create/delete files in C:\Users\xxx\AppData\Roaming\AWS SAM directory or file an issue at https://github.com/aws/aws-sam-cli/issues

@Tristanwhack
Copy link

Issue persists on SAM version 1.48.0

@guoliang
Copy link

still issue in 1.53.0

@RustyLobster
Copy link

RustyLobster commented Jul 21, 2022

Same here. still an issue with SAM CLI, version 1.53.0

  • env: Windows 11, SAM CLI, version 1.53.0
  • I was also having this error : details: (<class 'OSError'>, OSError(41, 'The directory is not empty') so I emptied the directory C:\Users\xxx\AppData\Local\Temp\tmp_6asyom5\aws-sam-cli-app-templates and the directory is not empty error bit was gone, clean.

I ran the following command on cmd as administrator with my aws profile as root, but still having the following error. What kind of permission am I missing to configure?:

> sam init --name lambda-nodejs16.x --no-interactive --dependency-manager npm --runtime nodejs16.x --app-template hello-world --architecture x86_64

Cloning from https://github.com/aws/aws-sam-cli-app-templates (process may take a moment)
Error: Unstable state when updating repo. Check that you have permissions to create/delete files in C:\Users\XXX\AppData\Roaming\AWS SAM directory or file an issue at https://github.com/aws/aws-sam-cli/issues

@jbrook10
Copy link

Same issue for me.

  • Env: Windows 10, SAM CLI, version 1.53.0
2022-07-21 16:26:49 [INFO]: Command: (not started) [C:\Program Files\Amazon\AWSSAMCLI\bin\sam.cmd init --name Fantasy.Nfl.Lifetime.Lambda --no-interactive --dependency-manager cli-package --runtime dotnet6 --app-template hello-world]
2022-07-21 16:26:54 [INFO]: 
Cloning from https://github.com/aws/aws-sam-cli-app-templates (process may take a moment)

2022-07-21 16:27:08 [INFO]: Error: Unstable state when updating repo. Check that you have permissions to create/delete files in C:\Users\xxx\AppData\Roaming\AWS SAM directory or file an issue at https://github.com/aws/aws-sam-cli/issues

@janivimal
Copy link

Facing same issue, gives permission error, even though running commands under admin mode:

Cloning from https://github.com/aws/aws-sam-cli-app-templates (process may take a moment)
Error: Unstable state when updating repo. Check that you have permissions to create/delete files in C:\Users\xxxxx\AppData\Roaming\AWS SAM directory or file an issue at https://github.com/aws/aws-sam-cli/issues

@allannvictor
Copy link

Same issue here too.

Windows 10, SAM CLI, version 1.53.0

Cloning from https://github.com/aws/aws-sam-cli-app-templates (process may take a moment) Error: Unstable state when updating repo. Check that you have permissions to create/delete files in C:\Users\ardt\AppData\Roaming\AWS SAM directory or file an issue at https://github.com/aws/aws-sam-cli/issues

@hawflau
Copy link
Contributor

hawflau commented Jul 22, 2022

Hey @kannan-kiwitech @Tristanwhack @guoliang @RustyLobster @jbrook10 @janivimal @allannvictor, I believe the issue you are seeing is the same as #4031. You have to opt-in to enable LongPath support in Windows: https://docs.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=powershell#enable-long-paths-in-windows-10-version-1607-and-later

TLDR: Run the following as administrator in Powershell:

New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem" `
-Name "LongPathsEnabled" -Value 1 -PropertyType DWORD -Force

@allannvictor
Copy link

@hawflau It's worked! Thanks!

@janivimal
Copy link

@hawflau - running this command did the trick ! Thank you for sharing this !

@SumantSrivastava
Copy link

Hey @kannan-kiwitech @Tristanwhack @guoliang @RustyLobster @jbrook10 @janivimal @allannvictor, I believe the issue you are seeing is the same as #4031. You have to opt-in to enable LongPath support in Windows: https://docs.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=powershell#enable-long-paths-in-windows-10-version-1607-and-later

TLDR: Run the following as administrator in Powershell:

New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem" `
-Name "LongPathsEnabled" -Value 1 -PropertyType DWORD -Force

worked for me too.. thanks!

@abinshihab
Copy link

@hawflau Thank you it is working with me

@keithwenzler
Copy link

Yes, works!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.