git-annex/Command/Unlock.hs
Joey Hess 6eb5c3f479 Do not preserve permissions and acls when copying files from one local git repository to another. Timestamps are still preserved as long as cp --preserve=timestamps is supported.
This avoids cp -a overriding the default mode acls that the user might have
set in a git repository.

With GNU cp, this behavior change should not be a breaking change, because
git-anex also uses rsync sometimes in the same situation, and has only ever
preserved timestamps when using rsync.

Systems without GNU cp will no longer use cp -a, but instead just cp.
So, timestamps will no longer be preserved. Preserving timestamps when
copying between repos is not guaranteed anyway.

Closes: #729757
2014-08-26 17:10:25 -07:00

59 lines
1.4 KiB
Haskell

{- git-annex command
-
- Copyright 2010 Joey Hess <joey@kitenet.net>
-
- Licensed under the GNU GPL version 3 or higher.
-}
module Command.Unlock where
import Common.Annex
import Command
import Annex.Content
import Utility.CopyFile
def :: [Command]
def =
[ c "unlock" "unlock files for modification"
, c "edit" "same as unlock"
]
where
c n = notDirect . command n paramPaths seek SectionCommon
seek :: CommandSeek
seek = withFilesInGit $ whenAnnexed start
{- The unlock subcommand replaces the symlink with a copy of the file's
- content. -}
start :: FilePath -> Key -> CommandStart
start file key = do
showStart "unlock" file
ifM (inAnnex key)
( ifM (checkDiskSpace Nothing key 0)
( next $ perform file key
, do
warning "not enough disk space to copy file"
next $ next $ return False
)
, do
warning "content not present; cannot unlock"
next $ next $ return False
)
perform :: FilePath -> Key -> CommandPerform
perform dest key = do
src <- calcRepo $ gitAnnexLocation key
tmpdest <- fromRepo $ gitAnnexTmpObjectLocation key
liftIO $ createDirectoryIfMissing True (parentDir tmpdest)
showAction "copying"
ifM (liftIO $ copyFileExternal CopyAllMetaData src tmpdest)
( do
liftIO $ do
removeFile dest
moveFile tmpdest dest
thawContent dest
next $ return True
, do
warning "copy failed!"
next $ return False
)