CouscousPHP / Couscous

Couscous is good.
https://couscous.io
Other
841 stars 104 forks source link

couscous deploy copy error: target could not be opened for writing #226

Open BenCrulis opened 5 years ago

BenCrulis commented 5 years ago

Context

I made some local changes in my git configuration, played with git submodules and branches and then suddenly couscous deploy ceased to work. I now always get the same error:

$ couscous deploy
Generating /path_to_project to /path_to_project/.couscous/generated
[notice] Executing cd "/path_to_project" && cp -r figures/ .couscous/generated/

Deploying the website
Cloning https://github.com/bencrulis/BDMA_M1_Project in /tmp/couscous_deploy_cqlLxP
Checking out branch gh-pages
Copying generated website

In Filesystem.php line 63:

  Failed to copy "/path_to_project/.couscous/generated/.git" to "/tmp/couscous_deploy_cqlLxP/.git" because target file could not be opened for writing.                                              

deploy [--repository REPOSITORY] [--branch BRANCH] [--config CONFIG] [--] [<source>]

Couscous seems to have the writing permission but the source is a file and the target is a folder.

The content of the .git file in question is

gitdir: ../.git/modules/website

What I tried

Couscous preview still works perfectly.

Although no commit or push was done, it also ceased to work when deploying from another machine.

I also hoped adding .git to the excluded folders in couscous.yml would change something but it didn't work.

BenCrulis commented 5 years ago

I found a workaround, it seems to work again by telling couscous to remove the .git file after html generation in its scripts section:

scripts:
    after:
        - rm .couscous/generated/.git
mnapoli commented 5 years ago

Hi, this is weird, Couscous should ignore hidden directories:

https://github.com/CouscousPHP/Couscous/blob/eee01977d66dd71bff5bb0dbb345e83e552c1129/src/Model/Project.php#L133

so it should not try to copy the .git directory at all 🤔

Can you confirm this is what Couscous is doing and this is the problem?

BenCrulis commented 5 years ago

Hi, I added some debug prints under $excludedDirectories at the end of Project.php to see what's excluded:

    echo "Debug:\n";
    foreach($excludedDirectories->toArray() as $thing){
        echo $thing;
        echo "\n";
    }

I ran a couscous preview and couscous deploy, it printed tons of files starting with a dot:

Debug:
vendor
website
.git
.gitignore
__pycache__

.Python
build
develop-eggs
dist
downloads
eggs
.eggs
lib
lib64
parts
sdist
var
wheels
.installed.cfg
MANIFEST
pip-log.txt
pip-delete-this-directory.txt
htmlcov
.tox
.coverage
.cache
nosetests.xml
coverage.xml
.hypothesis
.pytest_cache
local_settings.py
db.sqlite3
instance
.webassets-cache
.scrapy
docs/_build
target
.ipynb_checkpoints
.python-version
celerybeat-schedule
.env
.venv
env
venv
ENV
env.bak
venv.bak
.spyderproject
.spyproject
.ropeproject
site
.mypy_cache
.couscous
Debug:
vendor
website
.git
.gitignore
__pycache__

.Python
build
develop-eggs
dist
downloads
eggs
.eggs
lib
lib64
parts
sdist
var
wheels
.installed.cfg
MANIFEST
pip-log.txt
pip-delete-this-directory.txt
htmlcov
.tox
.coverage
.cache
nosetests.xml
coverage.xml
.hypothesis
.pytest_cache
local_settings.py
db.sqlite3
instance
.webassets-cache
.scrapy
docs/_build
target
.ipynb_checkpoints
.python-version
celerybeat-schedule
.env
.venv
env
venv
ENV
env.bak
venv.bak
.spyderproject
.spyproject
.ropeproject
site
.mypy_cache
.couscous

I tried another debug print:

    echo "Debug 2:\n";
    foreach ($finder as $thing) {
        echo $thing;
        echo "\n";
    }

This time, no dotted files are printed, only directories.

I suspect the problem does not come from this file as it seems to be specific to couscous deploy.

Thank you for looking into this, I have absolutely no php skill to look myself.