-
Notifications
You must be signed in to change notification settings - Fork 0
Force files existing on a target location to be removed when deploying with fileExistsBehavior as "OVERWRITE" #8
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
base: master
Are you sure you want to change the base?
Conversation
코멘트 몇 개 남깁니다.
|
이전 답변에 오류가 있어서, 다시 코멘트 남깁니다~ 문제가 "symlink가 overwrite 안된다"는 건데, 에러 로그는 mkdir에서 났다고 나오는 게 왜 그런건가요?다시 확인해보니, 제가 잘못된 로그를 첨부했었네요.😟
normal copy는 non-directory 파일에 대해서만 불리는 것 아닌가요?
symlink만 overwrite되는게 아니라 모든 non-directory 파일에 대해서 변경이 적용되는 건데 이게 의도하신 바가 맞나요?의도한바가 맞습니다.
테스트코드현재 테스트코드 구조로는 오류 현상을 재현하기 어려워서, 생략하려고 합니다.
|
저라면 이렇게 쓸 것 같다, 는 느낌으로 써봅니다. 제목: 이슈 넘버는 PR 맨 위에 쓰고, 제목에는 안씁니다. 제목은 이 PR을 적용하면 결과적으로 어떤 일이 벌어지는지 구체적으로 요약해서 적습니다.
(여기부터 본문) This closes aws#143. TL;DR(한줄 요약을 영어로 보통 이렇게 씁니다. 참고) When deploying, A long story why
|
저는 테스트는 "generate_normal_copy 함수에서 overwirte인 경우 rm_rf를 호출하는지를 확인"하는 것이면 충분하다고 생각합니다. 기능과 테스트가 동일하다고 하셨는데 그게 문제가 될까요? |
@spilist 이렇게 생각하는 이유는 크게 두가지입니다.
이미 installer_test.rb는 Mockist를 기반으로 테스트를 검증하고 있는데, ( ex. CopyCommand.copy 호출여부 검증 ) rm_rf를 Mockist으로 테스트하는 건 왜이리 찜찜한건지 제 생각을 더 정리해봐야겠어요. ㅎㅎ |
저는 " 문득 생각난 게 있는데 이런 식으로 구현을 바꾼다면 어떨까요? # installer.rb
def generate_normal_copy(i, absolute_source_path, destination)
...
when "OVERWRITE"
i.copy(absolute_source_path, destination, overwrite: true)
...
# install_instruction.rb
def copy(source, destination, overwrite: false)
destination = sanitize_dir_path(destination)
FileUtils.rm_rf(destination) if overwrite
...
end (보니까 @instruction_builder
.expects(:copy)
.with("deploy-archive-dir/src1", "dst1/src1", overwrite: true) |
이게 무슨 말인지 잘 모르겠어요. 변경사항은 그냥 rm_rf 만 추가된 것 같은데요. |
저는 대상이 directory 일 때 무조건 rm_rf 하는 것은 좀 위험하다고 생각이 드는데요. |
이 문장은 "(CopyCommand를 호출하기 전에, 파일을 삭제함으로써) 파일이 없는 경우에만 CopyCommand를 호출하도록 변경했다"는 것을 (엄청..ㅎㅎ..) 함축한거였습니다. 복사 경로에 파일이 존재하지 않는 경우만, CopyCommand를 호출해야한다는 주석을 고려했다는걸 알리고 싶어서, 이런 코멘트를 추가했었습니다. 휘동님이 정리해주신 풀리퀘스트에 제가 전달하고 싶은 내용이 포함되어 있어서, 위의 코멘트가 지워져도 좋을 것 같아요.
그리고 OVERWRITE 옵션은 무조건 파일을 덮어쓰는 기능이라고 생각하고 있는데요. non-directory 파일을 복사하려는데, 대상경로에 directory가 있고, 그 안에 파일이 존재하는 경우에는 오류를 리턴시킨다는건, OVERWRITE 목적과는 다르단 생각이 드네요. 기존 디렉토리가 삭제되는게 우려된다면, |
@spilist 이상하게도, |
저는 좀 다르게 생각하는데요. 기존에 위치한 것이 디렉토리인데 새로 배포되는 동일한 이름은 파일이라면 의도한 것이 아닐 가능성이 높다고 생각합니다. 그리고 일반적으로 OVERWRITE라는 용어가 file에서 file을 복사할 때 덮어씌우는 것을 의미하기 때문에 동일한 디렉토리가 있으면 지우고 파일로 대체하는 것을 기대하는 사람은 없다고 생각해요. linux에서도 cp명령어로 동일한 상황을 테스트해보았을 때의 경우도 살펴보면 file to file 이면 overwrite를 하겠는지 물어보고 y를 누르면 덮어씌워지지만,
|
사실 저도 이부분이 찝찝하긴 했었어요. 복사하려는 파일과 동일한 이름의 디렉토리가 존재하는 상황 자체가 비정상이라고 보면 이 경우에는 exception이 생기는게 더 나을지도 모르겠네요. |
@wonderer80 OVERWRITE 옵션을 사용할 때, 이 행동을 기대하진 않을 것 같아요. 그래서 이를 방어하는 방법으로 폴더를 삭제하는 방식을 사용했습니다. 그런데 명시적으로 오류를 리턴하는 방식으로 위의 상황을 막는게 좋겠군요. |
cf10098
to
b3c5071
Compare
파일을 삭제하는 로직을 추가했던건, Destination이 디렉토리인 경우 디렉토리 하위에 파일이 복사되는 현상을 막기 위함이였습니다. 그런데 non directory인 경우에만, CopyCommand가 호출된다면, |
f520cc1
to
0f5cb2a
Compare
TL;DRwhen deploying with fileExistsBehavior as "OVERWRITE" AND target location is not regular file ( symlink or directory ), Fix errors that occur.
A long story why OVERWRITE option doesn't work correctlyWhen creating a deployment, codedeploy handles files that already exist in a deployment target location but weren't part of the previous successful deployment with fileExistsBehavior option. If the option is OVERWRITE, the deployment should replace files in the target location to the source files. However, OVERWRITE doesn't work as expected when some conditions are met. Suppose my source file is source and destination is target_dir/source. Since I set fileExistsBehavior as OVERWRITE, I want to have a result of target_dir/source regardless of existence of the destination file. But if target_dir/source already exists, only 1 out of 4 cases works correctly.
If the target location was a directory (2, 4 Case), I didn't think it was the intended situation. so in this instance, explicitly exception was generated.
|
0f5cb2a
to
5ede9b6
Compare
Issue aws#143:
Summary
Fixed an error that caused the OVERWRITE option to behave abnormally if the source file is a symlink and the file already exists in the destination path. ( raise
Errno::EEXIST Exception
)Description of changes:
This PR makes the installer deletes the destination files before copying the files If using the OVERWIRTE option.
Reason
Errno::EEXIST Exception
can be avoided by adding theforce=> true
option toFileUtils.symlink
. ( inCopyCommand.execution()
function )FileUtils.copy
).issue error log sample
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.