cp -r stops with an exception #2329
Labels
No labels
c/code
c/code-dirnodes
c/code-encoding
c/code-frontend
c/code-frontend-cli
c/code-frontend-ftp-sftp
c/code-frontend-magic-folder
c/code-frontend-web
c/code-mutable
c/code-network
c/code-nodeadmin
c/code-peerselection
c/code-storage
c/contrib
c/dev-infrastructure
c/docs
c/operational
c/packaging
c/unknown
c/website
kw:2pc
kw:410
kw:9p
kw:ActivePerl
kw:AttributeError
kw:DataUnavailable
kw:DeadReferenceError
kw:DoS
kw:FileZilla
kw:GetLastError
kw:IFinishableConsumer
kw:K
kw:LeastAuthority
kw:Makefile
kw:RIStorageServer
kw:StringIO
kw:UncoordinatedWriteError
kw:about
kw:access
kw:access-control
kw:accessibility
kw:accounting
kw:accounting-crawler
kw:add-only
kw:aes
kw:aesthetics
kw:alias
kw:aliases
kw:aliens
kw:allmydata
kw:amazon
kw:ambient
kw:annotations
kw:anonymity
kw:anonymous
kw:anti-censorship
kw:api_auth_token
kw:appearance
kw:appname
kw:apport
kw:archive
kw:archlinux
kw:argparse
kw:arm
kw:assertion
kw:attachment
kw:auth
kw:authentication
kw:automation
kw:avahi
kw:availability
kw:aws
kw:azure
kw:backend
kw:backoff
kw:backup
kw:backupdb
kw:backward-compatibility
kw:bandwidth
kw:basedir
kw:bayes
kw:bbfreeze
kw:beta
kw:binaries
kw:binutils
kw:bitcoin
kw:bitrot
kw:blacklist
kw:blocker
kw:blocks-cloud-deployment
kw:blocks-cloud-merge
kw:blocks-magic-folder-merge
kw:blocks-merge
kw:blocks-raic
kw:blocks-release
kw:blog
kw:bom
kw:bonjour
kw:branch
kw:branding
kw:breadcrumbs
kw:brians-opinion-needed
kw:browser
kw:bsd
kw:build
kw:build-helpers
kw:buildbot
kw:builders
kw:buildslave
kw:buildslaves
kw:cache
kw:cap
kw:capleak
kw:captcha
kw:cast
kw:centos
kw:cffi
kw:chacha
kw:charset
kw:check
kw:checker
kw:chroot
kw:ci
kw:clean
kw:cleanup
kw:cli
kw:cloud
kw:cloud-backend
kw:cmdline
kw:code
kw:code-checks
kw:coding-standards
kw:coding-tools
kw:coding_tools
kw:collection
kw:compatibility
kw:completion
kw:compression
kw:confidentiality
kw:config
kw:configuration
kw:configuration.txt
kw:conflict
kw:connection
kw:connectivity
kw:consistency
kw:content
kw:control
kw:control.furl
kw:convergence
kw:coordination
kw:copyright
kw:corruption
kw:cors
kw:cost
kw:coverage
kw:coveralls
kw:coveralls.io
kw:cpu-watcher
kw:cpyext
kw:crash
kw:crawler
kw:crawlers
kw:create-container
kw:cruft
kw:crypto
kw:cryptography
kw:cryptography-lib
kw:cryptopp
kw:csp
kw:curl
kw:cutoff-date
kw:cycle
kw:cygwin
kw:d3
kw:daemon
kw:darcs
kw:darcsver
kw:database
kw:dataloss
kw:db
kw:dead-code
kw:deb
kw:debian
kw:debug
kw:deep-check
kw:defaults
kw:deferred
kw:delete
kw:deletion
kw:denial-of-service
kw:dependency
kw:deployment
kw:deprecation
kw:desert-island
kw:desert-island-build
kw:design
kw:design-review-needed
kw:detection
kw:dev-infrastructure
kw:devpay
kw:directory
kw:directory-page
kw:dirnode
kw:dirnodes
kw:disconnect
kw:discovery
kw:disk
kw:disk-backend
kw:distribute
kw:distutils
kw:dns
kw:do_http
kw:doc-needed
kw:docker
kw:docs
kw:docs-needed
kw:dokan
kw:dos
kw:download
kw:downloader
kw:dragonfly
kw:drop-upload
kw:duplicity
kw:dusty
kw:earth-dragon
kw:easy
kw:ec2
kw:ecdsa
kw:ed25519
kw:egg-needed
kw:eggs
kw:eliot
kw:email
kw:empty
kw:encoding
kw:endpoint
kw:enterprise
kw:enum34
kw:environment
kw:erasure
kw:erasure-coding
kw:error
kw:escaping
kw:etag
kw:etch
kw:evangelism
kw:eventual
kw:example
kw:excess-authority
kw:exec
kw:exocet
kw:expiration
kw:extensibility
kw:extension
kw:failure
kw:fedora
kw:ffp
kw:fhs
kw:figleaf
kw:file
kw:file-descriptor
kw:filename
kw:filesystem
kw:fileutil
kw:fips
kw:firewall
kw:first
kw:floatingpoint
kw:flog
kw:foolscap
kw:forward-compatibility
kw:forward-secrecy
kw:forwarding
kw:free
kw:freebsd
kw:frontend
kw:fsevents
kw:ftp
kw:ftpd
kw:full
kw:furl
kw:fuse
kw:garbage
kw:garbage-collection
kw:gateway
kw:gatherer
kw:gc
kw:gcc
kw:gentoo
kw:get
kw:git
kw:git-annex
kw:github
kw:glacier
kw:globalcaps
kw:glossary
kw:google-cloud-storage
kw:google-drive-backend
kw:gossip
kw:governance
kw:grid
kw:grid-manager
kw:gridid
kw:gridsync
kw:grsec
kw:gsoc
kw:gvfs
kw:hackfest
kw:hacktahoe
kw:hang
kw:hardlink
kw:heartbleed
kw:heisenbug
kw:help
kw:helper
kw:hint
kw:hooks
kw:how
kw:how-to
kw:howto
kw:hp
kw:hp-cloud
kw:html
kw:http
kw:https
kw:i18n
kw:i2p
kw:i2p-collab
kw:illustration
kw:image
kw:immutable
kw:impressions
kw:incentives
kw:incident
kw:init
kw:inlineCallbacks
kw:inotify
kw:install
kw:installer
kw:integration
kw:integration-test
kw:integrity
kw:interactive
kw:interface
kw:interfaces
kw:interoperability
kw:interstellar-exploration
kw:introducer
kw:introduction
kw:iphone
kw:ipkg
kw:iputil
kw:ipv6
kw:irc
kw:jail
kw:javascript
kw:joke
kw:jquery
kw:json
kw:jsui
kw:junk
kw:key-value-store
kw:kfreebsd
kw:known-issue
kw:konqueror
kw:kpreid
kw:kvm
kw:l10n
kw:lae
kw:large
kw:latency
kw:leak
kw:leasedb
kw:leases
kw:libgmp
kw:license
kw:licenss
kw:linecount
kw:link
kw:linux
kw:lit
kw:localhost
kw:location
kw:locking
kw:logging
kw:logo
kw:loopback
kw:lucid
kw:mac
kw:macintosh
kw:magic-folder
kw:manhole
kw:manifest
kw:manual-test-needed
kw:map
kw:mapupdate
kw:max_space
kw:mdmf
kw:memcheck
kw:memory
kw:memory-leak
kw:mesh
kw:metadata
kw:meter
kw:migration
kw:mime
kw:mingw
kw:minimal
kw:misc
kw:miscapture
kw:mlp
kw:mock
kw:more-info-needed
kw:mountain-lion
kw:move
kw:multi-users
kw:multiple
kw:multiuser-gateway
kw:munin
kw:music
kw:mutability
kw:mutable
kw:mystery
kw:names
kw:naming
kw:nas
kw:navigation
kw:needs-review
kw:needs-spawn
kw:netbsd
kw:network
kw:nevow
kw:new-user
kw:newcaps
kw:news
kw:news-done
kw:news-needed
kw:newsletter
kw:newurls
kw:nfc
kw:nginx
kw:nixos
kw:no-clobber
kw:node
kw:node-url
kw:notification
kw:notifyOnDisconnect
kw:nsa310
kw:nsa320
kw:nsa325
kw:numpy
kw:objects
kw:old
kw:openbsd
kw:openitp-packaging
kw:openssl
kw:openstack
kw:opensuse
kw:operation-helpers
kw:operational
kw:operations
kw:ophandle
kw:ophandles
kw:ops
kw:optimization
kw:optional
kw:options
kw:organization
kw:os
kw:os.abort
kw:ostrom
kw:osx
kw:osxfuse
kw:otf-magic-folder-objective1
kw:otf-magic-folder-objective2
kw:otf-magic-folder-objective3
kw:otf-magic-folder-objective4
kw:otf-magic-folder-objective5
kw:otf-magic-folder-objective6
kw:p2p
kw:packaging
kw:partial
kw:password
kw:path
kw:paths
kw:pause
kw:peer-selection
kw:performance
kw:permalink
kw:permissions
kw:persistence
kw:phone
kw:pickle
kw:pip
kw:pipermail
kw:pkg_resources
kw:placement
kw:planning
kw:policy
kw:port
kw:portability
kw:portal
kw:posthook
kw:pratchett
kw:preformance
kw:preservation
kw:privacy
kw:process
kw:profile
kw:profiling
kw:progress
kw:proxy
kw:publish
kw:pyOpenSSL
kw:pyasn1
kw:pycparser
kw:pycrypto
kw:pycrypto-lib
kw:pycryptopp
kw:pyfilesystem
kw:pyflakes
kw:pylint
kw:pypi
kw:pypy
kw:pysqlite
kw:python
kw:python3
kw:pythonpath
kw:pyutil
kw:pywin32
kw:quickstart
kw:quiet
kw:quotas
kw:quoting
kw:raic
kw:rainhill
kw:random
kw:random-access
kw:range
kw:raspberry-pi
kw:reactor
kw:readonly
kw:rebalancing
kw:recovery
kw:recursive
kw:redhat
kw:redirect
kw:redressing
kw:refactor
kw:referer
kw:referrer
kw:regression
kw:rekey
kw:relay
kw:release
kw:release-blocker
kw:reliability
kw:relnotes
kw:remote
kw:removable
kw:removable-disk
kw:rename
kw:renew
kw:repair
kw:replace
kw:report
kw:repository
kw:research
kw:reserved_space
kw:response-needed
kw:response-time
kw:restore
kw:retrieve
kw:retry
kw:review
kw:review-needed
kw:reviewed
kw:revocation
kw:roadmap
kw:rollback
kw:rpm
kw:rsa
kw:rss
kw:rst
kw:rsync
kw:rusty
kw:s3
kw:s3-backend
kw:s3-frontend
kw:s4
kw:same-origin
kw:sandbox
kw:scalability
kw:scaling
kw:scheduling
kw:schema
kw:scheme
kw:scp
kw:scripts
kw:sdist
kw:sdmf
kw:security
kw:self-contained
kw:server
kw:servermap
kw:servers-of-happiness
kw:service
kw:setup
kw:setup.py
kw:setup_requires
kw:setuptools
kw:setuptools_darcs
kw:sftp
kw:shared
kw:shareset
kw:shell
kw:signals
kw:simultaneous
kw:six
kw:size
kw:slackware
kw:slashes
kw:smb
kw:sneakernet
kw:snowleopard
kw:socket
kw:solaris
kw:space
kw:space-efficiency
kw:spam
kw:spec
kw:speed
kw:sqlite
kw:ssh
kw:ssh-keygen
kw:sshfs
kw:ssl
kw:stability
kw:standards
kw:start
kw:startup
kw:static
kw:static-analysis
kw:statistics
kw:stats
kw:stats_gatherer
kw:status
kw:stdeb
kw:storage
kw:streaming
kw:strports
kw:style
kw:stylesheet
kw:subprocess
kw:sumo
kw:survey
kw:svg
kw:symlink
kw:synchronous
kw:tac
kw:tahoe-*
kw:tahoe-add-alias
kw:tahoe-admin
kw:tahoe-archive
kw:tahoe-backup
kw:tahoe-check
kw:tahoe-cp
kw:tahoe-create-alias
kw:tahoe-create-introducer
kw:tahoe-debug
kw:tahoe-deep-check
kw:tahoe-deepcheck
kw:tahoe-lafs-trac-stream
kw:tahoe-list-aliases
kw:tahoe-ls
kw:tahoe-magic-folder
kw:tahoe-manifest
kw:tahoe-mkdir
kw:tahoe-mount
kw:tahoe-mv
kw:tahoe-put
kw:tahoe-restart
kw:tahoe-rm
kw:tahoe-run
kw:tahoe-start
kw:tahoe-stats
kw:tahoe-unlink
kw:tahoe-webopen
kw:tahoe.css
kw:tahoe_files
kw:tahoewapi
kw:tarball
kw:tarballs
kw:tempfile
kw:templates
kw:terminology
kw:test
kw:test-and-set
kw:test-from-egg
kw:test-needed
kw:testgrid
kw:testing
kw:tests
kw:throttling
kw:ticket999-s3-backend
kw:tiddly
kw:time
kw:timeout
kw:timing
kw:to
kw:to-be-closed-on-2011-08-01
kw:tor
kw:tor-protocol
kw:torsocks
kw:tox
kw:trac
kw:transparency
kw:travis
kw:travis-ci
kw:trial
kw:trickle
kw:trivial
kw:truckee
kw:tub
kw:tub.location
kw:twine
kw:twistd
kw:twistd.log
kw:twisted
kw:twisted-14
kw:twisted-trial
kw:twitter
kw:twn
kw:txaws
kw:type
kw:typeerror
kw:ubuntu
kw:ucwe
kw:ueb
kw:ui
kw:unclean
kw:uncoordinated-writes
kw:undeletable
kw:unfinished-business
kw:unhandled-error
kw:unhappy
kw:unicode
kw:unit
kw:unix
kw:unlink
kw:update
kw:upgrade
kw:upload
kw:upload-helper
kw:uri
kw:url
kw:usability
kw:use-case
kw:utf-8
kw:util
kw:uwsgi
kw:ux
kw:validation
kw:variables
kw:vdrive
kw:verify
kw:verlib
kw:version
kw:versioning
kw:versions
kw:video
kw:virtualbox
kw:virtualenv
kw:vista
kw:visualization
kw:visualizer
kw:vm
kw:volunteergrid2
kw:volunteers
kw:vpn
kw:wapi
kw:warners-opinion-needed
kw:warning
kw:weapi
kw:web
kw:web.port
kw:webapi
kw:webdav
kw:webdrive
kw:webport
kw:websec
kw:website
kw:websocket
kw:welcome
kw:welcome-page
kw:welcomepage
kw:wiki
kw:win32
kw:win64
kw:windows
kw:windows-related
kw:winscp
kw:workaround
kw:world-domination
kw:wrapper
kw:write-enabler
kw:wui
kw:x86
kw:x86-64
kw:xhtml
kw:xml
kw:xss
kw:zbase32
kw:zetuptoolz
kw:zfec
kw:zookos-opinion-needed
kw:zope
kw:zope.interface
p/blocker
p/critical
p/major
p/minor
p/normal
p/supercritical
p/trivial
r/cannot reproduce
r/duplicate
r/fixed
r/invalid
r/somebody else's problem
r/was already fixed
r/wontfix
r/worksforme
t/defect
t/enhancement
t/task
v/0.2.0
v/0.3.0
v/0.4.0
v/0.5.0
v/0.5.1
v/0.6.0
v/0.6.1
v/0.7.0
v/0.8.0
v/0.9.0
v/1.0.0
v/1.1.0
v/1.10.0
v/1.10.1
v/1.10.2
v/1.10a2
v/1.11.0
v/1.12.0
v/1.12.1
v/1.13.0
v/1.14.0
v/1.15.0
v/1.15.1
v/1.2.0
v/1.3.0
v/1.4.1
v/1.5.0
v/1.6.0
v/1.6.1
v/1.7.0
v/1.7.1
v/1.7β
v/1.8.0
v/1.8.1
v/1.8.2
v/1.8.3
v/1.8β
v/1.9.0
v/1.9.0-s3branch
v/1.9.0a1
v/1.9.0a2
v/1.9.0b1
v/1.9.1
v/1.9.2
v/1.9.2a1
v/cloud-branch
v/unknown
No milestone
No project
No assignees
5 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: tahoe-lafs/trac#2329
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
When I tried the same thing with the Tahoe-LAFS v1.10.0 release (from Ubuntu), it worked! So this is a regression.
Possibly caused by the fix to #712 (which was the last patch to touch the code where the error occurs: source:trunk/src/allmydata/scripts/tahoe_cp.py?annotate=blame#L767 )
Test (which fails) at https://github.com/tahoe-lafs/tahoe-lafs/commit/2329-test-0.
Review needed for the test.
warner will review the test, commit it with a TODO flag, then try to solve the original problem
So it looks like the intention of #712 was to make a command like
cp -r A LOCAL
orcp -r A LOCAL/
createLOCAL/A
. This depends upon "A" including a file or directory name (egcp -r DIRCAP/foo.txt LOCAL/
). But if A is a pure cap, then it has no human-meaningful name. What should get created in this case?I think the #2329 bug is resulting from a code path that assumes it will be provided with a name, and the pure-cap source argument doesn't give it one.
Well, what did it do in Tahoe-LAFS v1.10.0? (There are two cases: $CAP is a file cap, or a directory cap.)
From a tahoe-side tree with PARENTCAP, DIRCAP=PARENTCAP/dir, and FILECAP=PARENTCAP/dir/file.txt, and a local (real) target directory "local":
cp -r PARENTCAP/dir local/
->local/file.txt
cp -r DIRCAP local/
->local/file.txt
cp -r DIRCAP_ALIAS: local/
->local/file.txt
cp -r DIRCAP/file.txt local/
->local/file.txt
cp -r FILECAP local/
-> "error, you must specify a destination filename"local/
andlocal
behave the same waycp -r PARENTCAP/dir local/
->local/dir/file.txt
cp -r DIRCAP local/
-> (exception)cp -r DIRCAP_ALIAS: local/
-> (exception)cp -r DIRCAP/file.txt local/
->local/file.txt
cp -r FILECAP local/
-> "error, you must specify a destination filename"#712 fixed F to behave more like regular POSIX
/bin/cp
. I can think of three ways we might go with case G and H:1:
cp -r DIRCAP local/
should behave like an imaginarycp -r DIRCAP/* local/
would do (this is imaginary because we have no tahoe-side globs). In this example, it'd createlocal/file.txt
. This would match what it did in 1.10 (case B/C), but wouldn't match F. That'd be a shame, because we generally claim that "PARENTCAP/dir" and "DIRCAP" and "ALIAS:" are all interchangeable.2:
cp -r DIRCAP local/
would pretend that the source directory was named after the actual DIRCAP string (the ugly base32 representation), and createlocal/BASE32DIRCAP/file.txt
. Ick. For H we could use the alias name as a target name, so it'd createlocal/ALIASNAME/file.txt
, which is still lame but at least human-readable.3:
cp -r DIRCAP local/
would complain "you must specify a destination directory name", like cases E and J. This is somewhat plausible for G, and looks slightly weird for H.We don't have enough information to make case G behave like F.
Well, I guess I'm going to implement option 1: make
cp -r DIRCAP local/
behave like it used to (putting the contents of DIRCAP into local/) instead of like howcp -r PARENTCAP/dir local/
does now (making a new subdirectory under local/). It's not super consistent, but it's better than an exception.+1 for option 1.
When I said +1 for option 1, I was thinking that the previous behaviour of cases (B) and (C) --i.e. copying the contents of a dircap into a directory-- would become inexpressible. However I now understand the error in option 3 to be saying that "you must specify a previously nonexisting destination directory name". In that case you could still write:
cp -r DIRCAP local/missing -> local/missing
which would be consistent with cases (F) and (I), because
local/missing
becomes a copy ofDIRCAP
.If there were a tahoe-side globbing feature, the error messages in option 3 could say:
"""
To copy the contents of this dircap into an existing destination directory append /*; eg:
To create a new directory with the contents of this dircap, specify a new local directory name; eg:
A glob feature would allow the explicit indication of whether a bag, or the contents of the bag, should be copied.
Splitting by whether the destination exists or not:
cp -r PARENTCAP/dir local/
->local/file.txt
cp -r PARENTCAP/dir local/missing
-> ?cp -r DIRCAP local/
->local/file.txt
cp -r DIRCAP local/missing
-> ?cp -r DIRCAP_ALIAS: local/
->local/file.txt
cp -r DIRCAP_ALIAS: local/missing
-> ?cp -r DIRCAP/file.txt local/
->local/file.txt
cp -r DIRCAP/file.txt local/missing
->local/missing
cp -r FILECAP local/
-> "error, you must specify a destination filename"cp -r FILECAP local/missing
->local/missing
local/
andlocal
behave the same waycp -r PARENTCAP/dir local/
->local/dir/file.txt
cp -r PARENTCAP/dir local/missing
-> ?cp -r DIRCAP local/
-> (exception)cp -r DIRCAP local/missing
-> (exception?)cp -r DIRCAP_ALIAS: local/
-> (exception)cp -r DIRCAP_ALIAS: local/missing
-> (exception?)cp -r DIRCAP/file.txt local/
->local/file.txt
cp -r DIRCAP/file.txt local/missing
->local/missing
cp -r FILECAP local/
-> "error, you must specify a destination filename"cp -r FILECAP local/missing
->local/missing
Here's a proposal:
We determine whether the source means the bag, or the contents of the bag, according to this rule:
Note that the question of whether the source means the bag or the contents of the bag is not influenced by whether the target exists or doesn't exist.
This is another way of expressing proposal 1 from comment:398053.
I'm convinced globbing is too complicated if it evolves towards emulating bash. The key feature I was interested in comment:398057 was an explicit consistent way to disambiguate between container and contents.
So this could also be a
--contents
flag, or another non-globby-looking symbol, such as the presence of a trailing slash (which I believe warner suggested elsewhere).Examples:
Note that this can be orthogonal to whether or not dest/ exists.
Some semiconcrete examples:
tahoe cp -r myalias: foo/ # Error: "myalias:" has no name. To copy the contents into foo/ append a /
tahoe cp -r myalias:/ foo/ # foo will contain the contents of myalias after this.
tahoe cp -r URI:DIR2... foo/ # Error: a dircap has no name, to copy the contents, append a /
tahoe cp -r URI:DIR2.../ foo # Copy the contents of the cap into foo.
tahoe cp -r URI:DIR2.../blah foo # ./foo/blah/ will contain the contents.
tahoe cp -r URI:DIR2.../blah/ foo # ./foo will contain the contents.
Here's my attempt to fill out the table from comment:398058 for a certain rule that I have in my mind right now (written below).
cp -r PARENTCAP/dir local/
->local/dir/file.txt
cp -r PARENTCAP/dir local/missing
->local/missing/dir/file.txt
cp -r DIRCAP local/
->local/file.txt
cp -r DIRCAP local/missing
->local/missing/file.txt
cp -r DIRCAP_ALIAS: local/
->local/file.txt
cp -r DIRCAP_ALIAS: local/missing
->local/missing/file.txt
cp -r DIRCAP/file.txt local/
->local/file.txt
cp -r DIRCAP/file.txt local/missing
->local/missing
cp -r FILECAP local/
-> "error, you must specify a destination filename"cp -r FILECAP local/missing
->local/missing
"Rule comment:-1" is:
If the source is a directory:
If the target is the name of a locally existing file, then "error: there is already a local file present under the name $TARGET".
If the target is the name of something not locally existing, then mkdir it and then use it as "target directory".
If the target is the name of a locally existing directory, then proceed to use it as "target directory".
Check whether the source directory has a name (as in F1, F2) or has no name (as in G1, G2, H1, H2). If it has a name then we say that the source means the bag itself — the directory, and if it has no name then we say that the source means the contents of the bag — the contents of the directory.
Now if the source is the bag itself, then mkdir a new directory inside "target directory", named by the name of the source directory, and copy the contents of the bag into "target directory"/"source directory name"/ (which are cases F1 and F2).
Else (the source was the contents of the bag instead of the bag itself) copy the contents of the bag into "target directory"/ (which are cases G1, G2, H1, and H2).
If the source is a file, then check if the target is an existing directory.
If the source is a nameless file (as in J1, J2) and target is an existing directory (as in J1), then "error, you must specify a destination filename".
Else, if the source is a nameless file and the target is not an existing directory, then use the target as the local filename (which is case J2).
Else, if the source is a named file and the target is an existing directory, then use the source filename within the target existing directory (which is case I1).
Else, if the source is a named file and the target is not an existing directory, then use the target as the local filename (which is case I2).
"Rule comment:398061" could in the future be extended by additional syntax to indicate that the user wants to copy the contents-of-the-bag instead of the bag, in those cases where the bag had a name. comment:398060 suggests such additional syntax. (Side note: I have been confused in the past by the presence-or-absence-of-trailing-slash, such as rsync uses, to indicate this sort of thing. I'd prefer a very long and explicit thing like a command-line switch
--contents-of
.)Another argument against globbing is that the argument would have to be quoted -- and if it were not, strange things would happen on Unix (I think the argument would appear to be omitted assuming there is no local file that matches the glob).
Ok, here's the current state of affairs:
cp -r X local/
, wherelocal
already exists:cp -r X local/missing
, wherelocal
exists butmissing
does not:build_graphs()
,NoneType has no attribute startswith
error: you must specify a destination filename
put_file()
line 156,name
is None but precondition requiresisinstance(unicode)
I think zooko's rule in comment:398061 / comment:-1 gives us:
cp -r X local/
, wherelocal
already exists:cp -r X local/missing
, wherelocal
exists butmissing
does not:Although:
Feel free to edit the table in this comment if I interpreted your
proposal incorrectly.
warner: are you sure the table is right for
cp -R DIRCAP/file local/missing
, columns 1.10 and trunk? I would have expected the resulting file to be atlocal/missing
.My original comment:398061 was badly misformatted which hid some of the structure of my proposed rules. Here it is again, unchanged except for proper formatting.
Here's my attempt to fill out the table from comment:398058 for a certain rule that I have in my mind right now (written below).
cp -r PARENTCAP/dir local/
->local/dir/file.txt
cp -r PARENTCAP/dir local/missing
->local/missing/dir/file.txt
cp -r DIRCAP local/
->local/file.txt
cp -r DIRCAP local/missing
->local/missing/file.txt
cp -r DIRCAP_ALIAS: local/
->local/file.txt
cp -r DIRCAP_ALIAS: local/missing
->local/missing/file.txt
cp -r DIRCAP/file.txt local/
->local/file.txt
cp -r DIRCAP/file.txt local/missing
->local/missing
cp -r FILECAP local/
-> "error, you must specify a destination filename"cp -r FILECAP local/missing
->local/missing
"Rule comment:398061" is:
.1. If the source is a directory:
.a. If the target is the name of a locally existing file, then "error: there is already a local file present under the name $TARGET".
.b. If the target is the name of something not locally existing, then mkdir it and then use it as "target directory".
.c. If the target is the name of a locally existing directory, then proceed to use it as "target directory".
.d. Check whether the source directory has a name (as in F1, F2) or has no name (as in G1, G2, H1, H2). If it has a name then we say that the source means the bag itself — the directory, and if it has no name then we say that the source means the contents of the bag — the contents of the directory.
.2. If the source is a file, then check if the target is an existing directory.
.a. If the source is a nameless file (as in J1, J2) and target is an existing directory (as in J1), then "error, you must specify a destination filename".
.b. Else, if the source is a nameless file and the target is not an existing directory, then use the target as the local filename (which is case J2).
.c. Else, if the source is a named file and the target is an existing directory, then use the source filename within the target existing directory (which is case I1).
.d. Else, if the source is a named file and the target is not an existing directory, then use the target as the local filename (which is case I2).
Replying to warner:
That sounds okay to me.
I think the table is an accurate reflection of the comment:398061 / comment:398067 proposal.
Note that this could potentially interact with #2027.
Replying to daira:
Ping in case you missed this question.
D2 and I2, right? Yeah, those give local/missing/file.txt in both cases.
Ok, I agree that that's a bit weird.
/bin/cp
doesn't do that:/bin/cp parent/dir/file.txt local/missing
createslocal/missing
, and/bin/cp -r
does the same thing.I guess I need to add table entries for what unix does. If possible/applicable, we should match unix behavior.
I will try to implement zooko's algorithm from comment:398067 , and enhance the table to mention what happens with
/bin/cp
in both no-flag,-r
, and-R
cases.We discussed this during Nuts and Bolts, and I was persuaded that we should Zooko's comment:398067 algorithm despite the difference from
/bin/cp
(as tested on OS X). The clinching arguments were:/bin/cp
doesn't behave consistently across platforms anyway. Its different treatment of a trailing slash on some platforms is confusing and I don't think we should emulate that.Updated table for
cp [-r] X local/
, wherelocal
already exists:|
And for
cp [-r] X local/missing
, wherelocal
exists butmissing
does not:|
build_graphs()
,NoneType has no attribute startswith
put_file()
line 156,name
is None but precondition requiresisinstance(unicode)
I updated comment:398075 with the proposed behaviour from comment:398067. There is one case without
-r
that I didn't know how to fill in:tahoe cp PARENTCAP/dir local/
. (Eitherlocal/file
or ERROR-4b are reasonable possibilities.)In TC&C, we agreed that
tahoe cp PARENTCAP/dir local/
should also give ERROR-4.I've updated comment:398075 to reflect that (the rule is that you must give -r to copy a directory, so a directory-like source without -r gives an error). I think our table is now up to date.
Looking at the table, with an eye towards writing docs that explain what has changed, the new "cp -r PARENTCAP/dir local/missing" case (F2, bottom row) stands out. It's consistent with current trunk, but not with 1.10, or the proposed behavior for other directory-like sources, or with bin/cp. It'd be easier to explain if it were
local/missing/file
instead. I'm sure we've discussed this to death.. I've been too busy figuring out how to format that table. I'll reread the ticket and re-understand the rationale for that one.Next steps:
--help
docstringReplying to warner:
Let's see…
That is intentional in the comment:398067 algorithm. The reasoning is twofold:
First of all, the question of whether you want the bag vs. the contents of the bag is determined by whether the directory-like source has a name (the
F
column) vs. doesn't have a name (theG
andH
columns). That's a nice simple rule, and according to that, the result in the "comment:398067 -r" row has to belocal/missing/dir/file
instead oflocal/missing/file
, because the latter would be just the contents of the bag (file
) instead of the bag (dir/file
).So looking at the table, the cells of column
F
need to result indir/file
(if they aren't instead an error) and the cells of columnsG
andH
need to result infile
(if they aren't instead an error).Second, the comment:398067 algorithm behaves the same way whether the target exists or doesn't exist at the beginning of the algorithm. This is (in my intuition) a nice simple rule, and it also means there isn't a race condition in which the behavior is unpredictable because the existence of the target is unpredictable.
So looking at the table, that means the result of
F1
andF2
both need to result in the same behavior as each other.I'm not saying this rationale is better than other rationales that would justify other designs (such as “This is as much like
/bin/cp
as we could make it.”, or “The behavior is the same for all directory-like sources.”), but that's the rationale for this design.Yay!
Yay!
Yay!
Yay!
☺
Thank you for your good work on this.
I've got a branch which adds a test that exercises the full table. While studying how to change the code to let that test pass, I came across another wrinkle:
cp
accepts multiple source arguments.In general, if you have multiple source arguments, then the target must be a directory. If the target is a directory, then you can't use unnamed files as sources (one or multiple). The only case that accepts an unnamed file as a source is when you're copying exactly one of them to a target that is (or will be) a file.
Here's a list of what I think should happen (I tried to compress some of the cases.. let me know if it doesn't seem to cover everything):
Next step is to figure out how to turn this into a flowchart for
tahoe_cp.Copier.try_copy
.. I've started on the internal refactorings to make this easier (I was wrong before when I thought the basename should be tracked from outside ofTahoeFileSource
/etc.. treating it as a possibly-empty property of the source instance is totally the right way to do it).You're missing a case:
cp NAMEDANDUNNAMEDFILES.. X
: error: need a name (if there is >1 source of which >=1 is unnamed)Similarly for
cp -R X.. TO-DIR
:Ok, updates:
(https://github.com/warner/tahoe-lafs/tree/2329) has a branch that adds the tests (and some useful refactoring). It does not yet make any behavior changes. Take a look at the new
test_cli_cp.CopyOut
and see if it covers all those cases.Ok, the patch is ready for review: https://github.com/tahoe-lafs/tahoe-lafs/pull/143 . I rewrote the target-assignment code, cleaning up an awful lot in the process. I tried to make the diff as minimal as possible, but it may still look a bit ugly. The core 100-line cluster of functions was replaced by a different 100-line cluster of functions, but there's enough overlap that 'git diff' tries too hard to show you line-by-line changes, and does it badly. My best advice for reviewing it is to print out those 100 lines before, and those 100 lines after, and compare those two printouts, instead of looking at a detailed diff.
Two unexpected cases discovered during today's review:
We decided the first should signal an error: the trailing slash will only be accepted if the target is directory-like (either a pre-existing directory, or something missing that will be created as a directory, either because the source is a directory, or because there are multiple sources). If the target is directory-like, the trailing slash will not affect the copying behavior.
For the second, the realization was that this causes the contents of DIR1 and DIR2 to be merged together in the TARGETDIR, and thus the order of the source arguments matters (presumeably DIR2's contents will overwrite those of DIR1). The same thing happens if you copy multiple files of the same name into a directory (
cp foo/file.txt bar/file.txt outdir
).We need to ensure the implementation preserves the order of the source arguments (I think my current patch does, but if I'd used a set instead of a dict, it would behave differently). We should also double-check that
/bin/cp
does the same thing.I guess there are a couple of different forms we should examine.
cp -r foo/dir bar/dir TARGETDIR
cp -r DIRCAP1 DIRCAP2 TARGETDIR
The first is using two named directories that both happen to have the same name. This will cause
TARGETDIR/dir
to be created, and the contents of the sources merged into it.The second is using unnamed directories, triggering our "unnamed directories refer to the contents, not the bag itself" rule. Their contents will be merged into TARGETDIR.
/bin/cp
doesn't have unnamed directories, so the only way to simulate the contents-not-bag rule is to use/bin/cp -r DIR1/* DIR2/* TARGETDIR
, in which case any name collisions are obvious on the post-glob-expansion argv that's passed from the shell tocp
. I think (but I'm not sure) that the only way to wind up with collisions in/bin/cp
is if the basename of two SOURCE arguments are the same, since/bin/cp
always uses the basename of the source to create a child of the target.(in other words,
/bin/cp
may not actually give us precedent to follow)I think I was able to compress the rules above into the following set of assertions. These are the ones implemented by the code:
Copying files into files is easy. Copying things into directories requires looking at the type of each source object:
New pull request is up: https://github.com/tahoe-lafs/tahoe-lafs/pull/144
This incorporates all the review feedback so far. It also rejects trailing slashes on file-like targets, ensures in-order copies of colliding sources (last source wins), fixes a bug I uncovered that preventing colliding sources from working anyways, and adds a bunch more test cases.
Reviewing.
Ok, that PR (plus review feedback) has been landed, in e60392a. Remaining work: docs updates, and some notes for future cleanups.
Some notes from our review discussion, which didn't suggest changes to the current behavior, but which should be recorded for future analysis:
cp SOURCE1 SOURCE2 missing
is not so clear-cut. Current behavior is to mkdir, but maybe it should throw an error instead.cp SOURCE1 SOURCE2 missing/
is obviously referring to a directory, so mkdir is more correct. (current behavior is to mkdir). (/bin/cp
emits an error).cp -r SOURCE1 SOURCEDIR2 missing
is not clear-cut.Cleanups to do:
docs changes are in https://github.com/tahoe-lafs/tahoe-lafs/pull/162
In /tahoe-lafs/trac/commit/97fd19407d610de298c45500f7e1ad3e62b8a263:
ok, I think that's a wrap.
In /tahoe-lafs/trac/commit/ca23c4fa23a77b1fa557c734a2ad1f2abe4e7688: