Commit graph

421 commits

Author SHA1 Message Date
Joey Hess
c6f3c410d4 fix gpg pipeline stall
Bug introduced in d1da9cf221, where
I removed a forkProcess when feeding gpg. Feeding it from a thread
solves the bug.
2012-09-09 13:11:54 -04:00
Joey Hess
0c01348b65 pairing passphrase entry form, validation, etc
Actually 3 forms in one, this handles the initial passphrase entry, and the
confirmation, and also varys wording if the same user or a different user
is confirming.
2012-09-08 02:02:39 -04:00
Joey Hess
92df8250fa broke out Verifiable to a utility library, and added a quickcheck test 2012-09-07 23:23:52 -04:00
Joey Hess
faf3faa79d import yesod qualified
To avoid conflict with different liftIO from MonadIO (in some version of
yesod not the one I have here), and because it's generally clearer, since
this module has both Wai and Yesod stuff, to qualify them both.
2012-08-30 13:05:39 -04:00
Joey Hess
c9b3b8829d thread safe git-annex index file use 2012-08-24 20:50:39 -04:00
Joey Hess
5a68acb521 add NetWatcher thread
This deals with interruptions in network connectevity, by listening
for a new network interface coming up (using dbus to see when
network-manager or wicd do it), and forcing a rescan of
2012-08-21 19:58:53 -04:00
Joey Hess
dcd208513d Merge branch 'master' into assistant
Conflicts:
	debian/changelog
2012-08-17 08:22:43 -07:00
Joey Hess
fe8fee235b Pass --use-agent to gpg when in no tty mode. Thanks, Eskild Hustvedt. 2012-08-17 08:22:11 -07:00
Joey Hess
be310ac4d0 support building with yesod-default 1.1.0
Old 1.0.1 version is still supported as well. Cabal autodetects
which version is available, but in the Makefile, WITH_OLD_YESOD
has to be configured appropriately.

I have not squashed all the $newline warnings with the new Yesod.
They should go away eventually anyway as Yesod moves past that transition.
2012-08-09 13:33:04 -04:00
Joey Hess
e0cd977669 make pid file directory 2012-08-08 14:18:02 -04:00
Joey Hess
7e2d07484f Merge branch 'master' into assistant 2012-08-07 13:31:43 -04:00
Joey Hess
467669f00e update 2012-08-07 13:12:08 -04:00
Joey Hess
96d0a36f85 move comment 2012-08-07 11:10:41 -04:00
Joey Hess
40e9402fa5 add 2012-08-06 14:48:38 -04:00
Joey Hess
ac71ab7bd7 avoid head 2012-08-05 15:10:26 -04:00
Joey Hess
fd61354431 add 2012-08-05 14:50:00 -04:00
Joey Hess
e125ce74b8 work toward adding new repos on removable drives
This actually does add a new repo, but it doesn't yet set up
remotes, or sync to it.
2012-08-04 18:17:16 -04:00
Joey Hess
13a7362a1a fix xdg desktop dir lookup code
had to use xdg-user-dir to query it, since it's in a shell format file.
Fall back to
2012-08-02 23:51:38 -04:00
Joey Hess
9a038b4a9b better ~/ handling 2012-08-02 07:50:13 -04:00
Joey Hess
adf5789c1b fix bugs, add desktop dir 2012-08-02 07:47:20 -04:00
Joey Hess
60da0d6ad2 full autostart support
git annex assistant --autostart will start separate daemons in each
listed autostart repo

running the webapp outside any git-annex repo will open it on the
first listed autostart repo
2012-08-02 00:42:33 -04:00
Joey Hess
23fe661d37 install autostart file too 2012-08-01 23:31:53 -04:00
Joey Hess
9422e27489 installing desktop file working
Not hooked up to either Makefile or cabal yet
2012-08-01 20:49:02 -04:00
Joey Hess
89ec253a6a implement enough of the fdo specs to be able to write desktop menu files
to the appropriate system or local user directory
2012-08-01 20:27:45 -04:00
Joey Hess
8181b38ef6 write pid file even when running in foreground
This prevents multiple runs of the assistant in the foreground, and lets
--stop stop foregrounded runs too.

The webapp firstrun case also now writes a pid file, once it's made the git
repo to put it in.
2012-08-01 16:30:53 -04:00
Joey Hess
40c9973675 fix push status, broken when inParallel was adapted for -threaded
Before pushing ran in its own process, so exitSuccess was the right thing
to do, but with the threaded code, that's caught as an exception.
2012-07-30 11:52:44 -04:00
Joey Hess
d62b157194 better ordering of alerts 2012-07-29 19:05:51 -04:00
Joey Hess
ea05ba893c fix the auto token leak on auth error page issue permanantly 2012-07-29 12:12:14 -04:00
Joey Hess
6a9abf6526 add NotificationID to StatusR, and use it to block 2012-07-28 21:21:22 -04:00
Joey Hess
5be5cb219f add derives needed for use with Yesod, and fix a bug 2012-07-28 21:11:40 -04:00
Joey Hess
109dc122da add a newtype 2012-07-28 20:30:46 -04:00
Joey Hess
a17fde22fa add a NotificationBroadcaster to DaemonStatus
First use of it is to make the status checkpointer thread block until
there is really a change to the status.
2012-07-28 16:09:34 -04:00
Joey Hess
ca478b7bcb Focus today was writing a notification broadcaster.
This is a way to send a notification to a set of clients, any of which can be
blocked waiting for a new notification to arrive. A complication is that any
number of clients may be be dead, and we don't want stale notifications for
those clients to pile up and leak memory.

It took me 3 tries to find the solution, which turns out to be simple: An array
of SampleVars, one per client. Using SampleVars means that clients only see the
most recent notification, but when the notification is just "the assistant's
state changed somehow; display a refreshed rendering of it", that's sufficient.
2012-07-28 15:41:49 -04:00
Joey Hess
02ec8ea012 much better webapp startup of the assistant
This avoids forking another process, avoids polling, fixes a race,
and avoids a rare forkProcess thread hang that I saw once time
when starting the webapp.
2012-07-27 15:33:24 -04:00
Joey Hess
c93b546ebd remove bogus AI_NUMERICSERV
Not needed, and causes a segfault on OSX when it tries to dereference the
NULL servicename. (Linux handles this case better.)
2012-07-27 14:06:06 -04:00
Joey Hess
615dc09ffc use widgetFile 2012-07-26 22:54:31 -04:00
Joey Hess
9fd03c65f9 webapp now does long polling
The webapp is now a constantly updating clock! I accomplished this amazing
feat using "long polling", with some jquery and a little custom java
script.

There are more modern techniques, but this one works everywhere.
2012-07-26 17:56:24 -04:00
Joey Hess
2f775ef3e3 fix OSX open call 2012-07-26 12:59:40 -04:00
Joey Hess
95f4b192f0 on second thought, the session cookie is still useful to support setMessage 2012-07-26 12:41:20 -04:00
Joey Hess
cccdb44874 git annex webapp --force forces a restart of the daemon
Useful for testing..
2012-07-26 11:52:49 -04:00
Joey Hess
6cecc26206 update build deps 2012-07-26 05:13:27 -04:00
Joey Hess
9d6b59d0e2 use the secret token for authentication, and add to all dynamic urls 2012-07-26 04:50:09 -04:00
Joey Hess
b36804d648 generate random token and launch webapp using it 2012-07-26 03:38:20 -04:00
Joey Hess
3ac2cf09e5 added a custom defaultLayout, static site, and favicon
Broke hamlet out into standalone files.

I don't like the favicon display; it should be served from /favicon.ico,
but I could only get the static site to serve /static/favicon.ico, so
I had to use a <link rel=icon> to pull it in. I looked at
Yesod.Default.Handlers.getFaviconR, but it doesn't seem to embed
the favicon into the binary?
2012-07-26 02:45:01 -04:00
Joey Hess
1ffef3ad75 git annex webapp now opens a browser to the webapp
Also, starts the assistant if it wasn't already running.
2012-07-25 23:13:01 -04:00
Joey Hess
32d3cffc4c run yesod, and launch webapp on startup 2012-07-25 21:26:13 -04:00
Joey Hess
4ec9244f1a add a path field to remotes
Also broke out some helper functions around constructing remotes,
to be used later.
2012-07-22 14:30:43 -04:00
Joey Hess
f6d4786b86 left unsafe imports here; added a comment with a rationalle 2012-07-20 15:07:48 -04:00
Joey Hess
9d26b532ab use safe FFI imports for diskfree
There's a minor performance overhead to doing this, but this way I don't
have to worry about a situation where statfs might block for a long time.
For example, when it's on a network filesystem.
2012-07-20 15:03:58 -04:00
Joey Hess
da4c506d61 use safe FFI imports
This avoids blocking all threads when calling waitchange_kqueue,
which blocks.
2012-07-20 15:03:24 -04:00
Joey Hess
0496a3971d store whole Mntents
This way, if a mount point was already mounted, but something else
gets mounted there, it'll be seen as a new mount.
2012-07-19 21:25:26 -04:00
Joey Hess
ac044de486 cleanup 2012-07-19 21:20:38 -04:00
Joey Hess
4bcc92abd7 now working on OSX
While this seems to work fine when used in a simple program,
when I load it in ghci, it segfaults about half the time. Don't know why,
and seems ghci specific, but if I get reports of crashes, I'll need to look
into that.
2012-07-19 21:19:29 -04:00
Joey Hess
f768cddf3a fix build on OSX 2012-07-19 20:44:58 -04:00
Joey Hess
107a7b9388 try to make Utility.Mounts portable
This is an unholy mashup, but it just might work. It works on Linux,
that's all I've tested. :)
2012-07-19 20:38:58 -04:00
Joey Hess
e2c86a4b58 extacted Mounts.hsc from hsshellscript
Converted from using c2hs to using hsc2hs, just because other code
in git-annex uses hsc2hs.

Various cleanups.

This code is LGPLed, so I had to include that licence.
2012-07-19 12:53:39 -04:00
Joey Hess
1e0b7dda8c foo 2012-07-19 01:02:22 -04:00
Joey Hess
9fc94d780b better readProcess 2012-07-19 00:57:40 -04:00
Joey Hess
1db7d27a45 add back debug logging
Make Utility.Process wrap the parts of System.Process that I use,
and add debug logging to them.

Also wrote some higher-level code that allows running an action
with handles to a processes stdin or stdout (or both), and checking
its exit status, all in a single function call.

As a bonus, the debug logging now indicates whether the process
is being run to read from it, feed it data, chat with it (writing and
reading), or just call it for its side effect.
2012-07-19 00:46:52 -04:00
Joey Hess
2edb5d145c rewrote to not use forkProcess
That can make the threaded runtime stall.. But it can use threads now!
2012-07-18 19:25:46 -04:00
Joey Hess
f520a2c103 add missing imports 2012-07-18 18:29:33 -04:00
Joey Hess
f2ed3d6c8e Merge branch 'threaded' into assistant 2012-07-18 18:17:33 -04:00
Joey Hess
d1da9cf221 switch from System.Cmd.Utils to System.Process
Test suite now passes with -threaded!

I traced back all the hangs with -threaded to System.Cmd.Utils. It seems
it's just crappy/unsafe/outdated, and should not be used. System.Process
seems to be the cool new thing, so converted all the code to use it
instead.

In the process, --debug stopped printing commands it runs. I may try to
bring that back later.

Note that even SafeSystem was switched to use System.Process. Since that
was a modified version of code from System.Cmd.Utils, it needed to be
converted too. I also got rid of nearly all calls to forkProcess,
and all calls to executeFile, which I'm also doubtful about working
well with -threaded.
2012-07-18 18:00:24 -04:00
Joey Hess
05310538ef more debugging 2012-07-18 13:31:00 -04:00
Joey Hess
fb85d8e563 cleanup 2012-07-17 18:36:51 -04:00
Joey Hess
62a35162a0 bugfix 2012-07-17 18:35:56 -04:00
Joey Hess
32ac773934 kqueue: properly call delHook for file deletion, not delDirHook 2012-07-17 18:32:55 -04:00
Joey Hess
30ac6d7be0 robustness fix
Don't fall over symlinks, and avoid crashing if the file goes away.
2012-07-17 16:29:49 -04:00
Joey Hess
7d89cf0eb9 cleanup 2012-07-17 16:02:29 -04:00
Joey Hess
e816776a62 add inodes to kqueue's directory cache
This is necessary to generate events when a file is deleted and immediately
replaced. Otherwise, the cache will have the old file, and so no event
would be generated.

Use of getFileStatus is suboptimal, it would be faster to use
the inode returned by readdir -- but getDirectoryContents does not expose
it, so I'd have to copy and modify a lot of low-level code.
2012-07-17 15:57:49 -04:00
Joey Hess
182526ff68 add debugging 2012-07-17 14:40:05 -04:00
Joey Hess
3ea708e03b Merge branch 'master' into assistant 2012-07-02 15:45:20 -04:00
Joey Hess
7daa269853 better pid file locking code 2012-07-02 13:47:32 -04:00
Joey Hess
74f0d67aa3 avoid untrappable exception if dirContentsRecursive is run on a directory
that doesn't exist, or cannot be read

The problem is its use of unsafeInterleaveIO, which causes its IO code
to run when the thunk is forced, outside any exception trapping the caller
may do.
2012-07-02 10:56:26 -04:00
Joey Hess
bea0ac0274 record transfers for git-annex-shell
Not yet tested and places git-annex-shell is run need to be modified to
pass the new field settings.

Note that rsyncServerSend was changed to fork, rather than directly exec
rsync, because it needs to keep the transfer lock held, and clean up the
transfer log when done.
2012-07-02 01:31:10 -04:00
Joey Hess
d1f49b0ad0 add fields to git-annex-shell 2012-07-02 00:53:00 -04:00
Joey Hess
7625319c2c Merge branch 'master' into assistant 2012-07-01 21:00:43 -04:00
Joey Hess
29335bf326 pointlessness 2012-06-29 10:00:05 -04:00
Joey Hess
638a321ca5 typo 2012-06-28 14:15:49 -04:00
Joey Hess
421f9ce0e2 fix kqueue build 2012-06-28 14:13:15 -04:00
Joey Hess
4888c5b042 improve thread termination handling
The reason the DirWatcher had to wait for program termination was because
it used withINotify, so when it finished, its watcher threads were killed.
But since I have two DirWatcher threads now, that was not good, and could
perhaps explain the MVar problem I saw yesterday. In any case, fixed this
part of the code by making the DirWatcher return a handle that can be used
to stop it, and now the main Assistant thread is the only one calling
waitForTermination.
2012-06-28 13:37:03 -04:00
Joey Hess
67c8ef7de2 use a TMVar
SampleMVar won't work; between getting the current value and changing
it, another thread could made a change, which would get lost.

TMVar works well; this update situation is handled by atomic transactions.
2012-06-26 19:21:44 -04:00
Joey Hess
5cfe91f06d add a push retry thread 2012-06-25 16:38:12 -04:00
Joey Hess
a71e7161fc golfing 2012-06-23 01:33:10 -04:00
Joey Hess
e699ce1841 added a merger thread
Wow! I can create a file in repo a, and it instantly* shows up in repo b!

* under 1 second anyway
2012-06-22 17:01:08 -04:00
Joey Hess
e9630e90de the syncer now pushes out changes to remotes, in parallel
Note that, since this always pushes branch synced/master to the remote, it
assumes that master has already gotten all the commits that are on the
remote merged in. Otherwise, fast-forward prevention may prevent the push.

That's probably ok, because the next stage is to automatically detect
incoming pushes and merge.
2012-06-22 15:49:48 -04:00
Joey Hess
28e28bc043 stub syncer thread and commit channel 2012-06-22 14:10:25 -04:00
Joey Hess
ad11de94e5 typo 2012-06-20 15:53:56 -04:00
Joey Hess
483b1b08c6 Merge branch 'master' into watch 2012-06-20 13:15:59 -04:00
Joey Hess
75b6ee81f9 avoid ByteString.Char8 where not needed
Its truncation behavior is a red flag, so avoid using it in these places
where only raw ByteStrings are used, without looking at the data inside.
2012-06-20 13:13:40 -04:00
Joey Hess
ee2acd474f [Word8] to filesystem encoded String
My, GHC makes this hard.
2012-06-20 12:51:25 -04:00
Joey Hess
5580af5789 add closingTracked flag 2012-06-19 10:22:36 -04:00
Joey Hess
e68b3c99f4 kqueue synthetic add events on startup 2012-06-19 10:08:06 -04:00
Joey Hess
2a61df23e7 kqueue recursive directory adding 2012-06-19 09:56:03 -04:00
Joey Hess
4ab9449cee add eventsCoalesce 2012-06-19 02:23:45 -04:00
Joey Hess
fd3e945932 fix prototype 2012-06-19 01:57:19 -04:00
Joey Hess
03b9341356 fix scheduling
Handle kevent interruptions in the haskell code, so it can yield to other threads
2012-06-19 04:52:55 +00:00
Joey Hess
02e9fdb0a5 kqueue build fix
new event dispatch seems a bit broken though
2012-06-19 04:07:48 +00:00
Joey Hess
7a09d74319 lifted out the kqueue and inotify to a generic DirWatcher interface
Kqueue code for dispatching events is not tested and probably doesn't
build.
2012-06-18 23:49:07 -04:00
Joey Hess
e164553272 robustness fixes 2012-06-19 02:13:26 +00:00
Joey Hess
5e9fdac92f update kqueue when new directories are added 2012-06-18 21:46:04 -04:00
Joey Hess
2bfcc0b09c kqueue: add directory content tracking, and change determination
This *may* now return Add or Delete Changes as appropriate. All I know
for sure is that it compiles.

I had hoped to avoid maintaining my own state about the content of the
directory tree, and rely on git to check what was changed. But I can't;
I need to know about new and deleted subdirectories to add them to the
watch list, and git doesn't deal with (empty) directories.

So, wrote all the code to scan directories, remember their past contents,
compare with current contents, generate appropriate Change events, and
update bookkeeping info appropriately.
2012-06-18 21:29:30 -04:00
Joey Hess
ae7d07ddcb close fds 2012-06-18 19:14:58 -04:00
Joey Hess
b141d9bcc8 retry interrupted kevent calls
Many thanks to geekosaur in #haskell for help with this.
2012-06-18 18:03:50 -04:00
Joey Hess
a11825a1f1 add test stub 2012-06-18 16:56:05 -04:00
Joey Hess
d680ff7ef0 kqueue code compiles on debian kfreebsd 2012-06-18 16:34:08 -04:00
Joey Hess
90d565149a flesh out kqueue library
Have not tried to build this yet. But barring minor mistakes, I think it's
good.
2012-06-18 16:18:59 -04:00
Joey Hess
89fcee03d0 add some utility functions for later
Will need to update the DirMap to add or remove subdirs.
2012-06-18 13:22:36 -04:00
Joey Hess
a39b73d118 recurse dirTree and open the directories for kqueue to watch 2012-06-18 13:01:58 -04:00
Joey Hess
dc3d9d1e98 added dirTree 2012-06-18 12:53:57 -04:00
Joey Hess
3c8a9043b6 skeleton C library for calling kqueue 2012-06-18 12:25:20 -04:00
Joey Hess
66344a3613 Enable diskfree on kfreebsd, using statvfs.
Could not reproduce the build failure I had seen related to this,
but the numbers were wrong with statfs64. Probably pulling from the wrong
place in the structure. statvfs seems to work..
2012-06-17 18:10:57 -04:00
Joey Hess
e84b78f40c reorg 2012-06-17 14:02:40 -04:00
Joey Hess
0052cec2b7 add lsof build deps
Check for it in configure; and add a --force option for people without it
who want to live dangerously.
2012-06-15 23:29:39 -04:00
Joey Hess
bb6074dfea work around a wrinkle in how lsof handles hard links to files that are open elsewhere
+d is probably more expensive, but I need it
2012-06-15 22:34:42 -04:00
Joey Hess
d91950ecba cleanup 2012-06-15 22:16:13 -04:00
Joey Hess
96ac25094b fix pid file writing
need to truncate, or part of previous longer pid may be left after writing
2012-06-15 20:42:53 -04:00
Joey Hess
85db1720e9 add lsof interface
Uses lsof -F0 to get machine-readable output
2012-06-15 15:13:31 -04:00
Joey Hess
4b2b5e820e add 2012-06-15 14:11:09 -04:00
Joey Hess
36d73b0017 slightly higher-level thread scheduling code
Including support for unbound thread sleeping. Haskell's max thread sleep
is 37 minutes, due to maxBound Int!
2012-06-13 17:53:19 -04:00
Joey Hess
12dbb9d1d0 plumb file status through to event handlers
The idea, not yet done, is to use this to detect when a file
has an old change time, and avoid expensive restaging of the file.

If git-annex watch keeps track of the last time it finished a full scan,
then any symlink that is older than that time must have been scanned
before, so need not be added. (Relying on moving, copying, etc of a file
all updating its change time.)

Anyway, this info is available for free since inotify already checks it,
so it might as well make it available.
2012-06-13 01:20:37 -04:00
Joey Hess
b240418acc better optimisation of add check
Now really only done in the startup scan.

It turns out to be quite hard for event handlers to know when the startup
scan is complete. I tried to make addWatch pass that info, but found
threading the state very difficult. For now, a quick hack, using the fast
flag.

Note that it's actually possible for inotify events to come in while the
startup scan is still ongoing. Due to my hack, the expensive check will
be done for files added in such inotify events.
2012-06-12 16:24:06 -04:00
Joey Hess
7d2c813396 fix bug that turned files already in git into symlinks
This requires a relatively expensive test at file add time to see if it's
in git already. But it can be optimised to only happen during the startup
scan.
2012-06-12 15:57:24 -04:00
Joey Hess
535d9e4998 add a flag indicating if an event was synthesized during initial dir scan 2012-06-12 14:34:09 -04:00
Joey Hess
942d8f7298 hlint 2012-06-12 11:32:06 -04:00
Joey Hess
433ff41496 bugfix 2012-06-11 02:06:22 -04:00
Joey Hess
d0a0a6ae21 git annex watch --stop 2012-06-11 02:01:20 -04:00
Joey Hess
8539a7bde8 fix pid file locking
Ok, that's odd.. opening it before fork breaks the locking.
I don't understand why.
2012-06-11 01:37:25 -04:00
Joey Hess
0b3e2bed78 add a pid file
Writes pid to a file. Is supposed to take an exclusive lock, but that's not
working, and it's too late for me to understand why.
2012-06-11 01:20:19 -04:00
Joey Hess
d5884388b0 daemonize git annex watch 2012-06-11 00:39:09 -04:00
Joey Hess
5d4e09199c update message based on user feedback 2012-06-07 00:47:09 -04:00
Joey Hess
b8ae9528ab refactor 2012-06-06 23:20:09 -04:00
Joey Hess
b8f85f7a82 build watch on non-linux, just don't do anything 2012-06-06 22:49:32 -04:00
Joey Hess
c5b11561f0 handle running out of watch descriptors 2012-06-06 16:50:28 -04:00
Joey Hess
db8effb8f3 ignore .gitignore and .gitattributes 2012-06-06 15:50:12 -04:00
Joey Hess
993e6459a3 factor out nukeFile 2012-06-06 13:13:13 -04:00
Joey Hess
cbf16f1967 refactor 2012-06-04 19:43:29 -04:00
Joey Hess
5b4e5ce7e5 deletion
When a new file is annexed, a deletion event occurs when it's moved away
to be replaced by a symlink. Most of the time, there is no problimatic
race, because the same thread runs the add event as the deletion event.
So, once the symlink is in place, the deletion code won't run at all,
due to existing checks that a deleted file is really gone.

But there is a race at startup, as then the inotify thread is running
at the same time as the main thread, which does the initial tree walking
and annexing. It would be possible for the deletion inotify to run
in a perfect race with the addition, and remove the newly added symlink
from the git cache.

To solve this race, added event serialization via a MVar. We putMVar
before running each event, which blocks if an event is already running.
And when an event finishes (or crashes!), we takeMVar to free the lock.

Also, make rm -rf not spew warnings by passing --ignore-unmatch when
deleting directories.
2012-06-04 18:09:18 -04:00
Joey Hess
529a3721e1 refactor 2012-06-04 17:17:05 -04:00
Joey Hess
47f8f43715 workaround other part of moved directory problem
This fixes the scenario where:

* directory foo is moved away (and still watched)
* a new directory foo is made
* file (or directory) foo/bar is created
* the old directory's file (or directory) "bar" is deleted

We don't want a deletion event for foo/bar in this case.
2012-06-04 14:54:14 -04:00
Joey Hess
fa9d479fd1 add explict test that a closed file even is on a regular file
There are two reasons for this test. First, there could be a fifo or other
non-regular file that was closed.

Second, this test avoids ugliness when a subdirectory is moved out of the
top of the watch directory to elsewhere, and a file added to it.
Since the subdirectory has moved, the file won't be present under the
old location, and nothing will be done.

I cannot find a way to stop watching such directories, at least not without
a lot of pain. The inotify interface in Haskell doesn't make it easy to
stop watching a given subdirectory when it's moved out; it would require
keeping a map of all watch handles that is shared between threads.
This workaround avoids the problem in most cases; the only remaining case
being deletion of a file from a moved subdirectory.
2012-06-04 14:31:06 -04:00
Joey Hess
23dbff4b43 add events for symlink creation and directory removal
Improved the inotify code, so it will also notice directory removal
and symlink creation.

In the watch code, optimised away a stat of a file that's being added,
that's done by Command.Add.start. This is the reason symlink creation is
handled separately from file creation, since during initial tree walk
at startup, a stat was already done, and can be reused.
2012-06-04 13:22:56 -04:00
Joey Hess
3b09281b44 add dirContentsRecursive 2012-05-31 19:25:33 -04:00
Joey Hess
bb4f31a0ee Clean up handling of git directory and git worktree.
Baked into the code was an assumption that a repository's git directory
could be determined by adding ".git" to its work tree (or nothing for bare
repos). That fails when core.worktree, or GIT_DIR and GIT_WORK_TREE are
used to separate the two.

This was attacked at the type level, by storing the gitdir and worktree
separately, so Nothing for the worktree means a bare repo.

A complication arose because we don't learn where a repository is bare
until its configuration is read. So another Location type handles
repositories that have not had their config read yet. I am not entirely
happy with this being a Location type, rather than representing them
entirely separate from the Git type. The new code is not worse than the
old, but better types could enforce more safety.

Added support for core.worktree. Overriding it with -c isn't supported
because it's not really clear what to do if a git repo's config is read, is
not bare, and is then overridden to bare. What is the right git directory
in this case? I will worry about this if/when someone has a use case for
overriding core.worktree with -c. (See Git.Config.updateLocation)

Also removed and renamed some functions like gitDir and workTree that
misused git's terminology.

One minor regression is known: git annex add in a bare repository does not
print a nice error message, but runs git ls-files in a way that fails
earlier with a less nice error message. This is because before --work-tree
was always passed to git commands, even in a bare repo, while now it's not.
2012-05-18 17:03:12 -04:00
Joey Hess
e36808e167 Pass -a to cp even when it supports --reflink=auto, to preserve permissions.
Amoung other things, this makes unlocking a WORM backed file and then
re-adding it without making any changes not add a new object, as the
timestamp is preserved.
2012-05-15 14:18:51 -04:00
Joey Hess
913775410b update 2012-05-02 11:43:30 -04:00
Joey Hess
5337c4e0c4 rsync protocol? 2012-05-02 11:38:27 -04:00
Joey Hess
0c9c14b52f percentage library 2012-04-29 17:48:07 -04:00
Joey Hess
1c16f616df Added shared cipher mode to encryptable special remotes.
This option avoids gpg key distribution, at the expense of flexability, and
with the requirement that all clones of the git repository be equally
trusted.
2012-04-29 14:02:43 -04:00
Joey Hess
f766774209 unbreak code inside ifdef 2012-04-22 11:22:20 -04:00
Joey Hess
42e4145a17 bugfixes 2012-04-22 01:20:17 -04:00
Joey Hess
84ac8c58db Add annex.httpheaders and annex.httpheader-command config settings
Allow custom headers to be sent with all HTTP requests.

(Requested by the Internet Archive)
2012-04-22 01:13:09 -04:00
Joey Hess
ed79596b75 noop 2012-04-21 23:32:33 -04:00
Joey Hess
bee420bd2d in which I discover void
void :: Functor f => f a -> f () -- ah, of course that's useful :)
2012-04-21 23:06:19 -04:00
Joey Hess
b98b69e8c6 honor core.sharedRepository when making all the other files in the annex
Lock files, directories, etc.
2012-04-21 19:36:03 -04:00
Joey Hess
7e45712d19 better file mode setting code 2012-04-21 16:01:56 -04:00
Joey Hess
b4a5e39ee6 Support git's core.sharedRepository configuration
This is incomplete, it does not honor it yet for hash directories
and other annex bookkeeping files. Some of that is not needed for a bare
repo; some of it may be.
2012-04-21 15:36:52 -04:00
Joey Hess
cbf9a9420e avoid chown call if the current file mode is same as new
Not only an optimisation. fsck always tried to preventWrite to make sure
file modes are good, and in a shared repo, that will fail on directories
not owned by the current user. Although there may be other problems with
such a setup.
2012-04-21 11:59:50 -04:00
Joey Hess
37061c019d tweak 2012-04-18 13:23:46 -04:00
Joey Hess
d75771b0ab clear errno after successful call
When preparing the debian stable backport, I am seeing a call to statvfs()
succeed, but also set errno to 2 (ENOENT). Not sure why this happens;
I am in a schroot when it does happen, or perhaps stable's libc is a little
broken and sets errno incorrectly. Anyway, it should be perfectly fine to
clear errno after the successful call, rather than before it.
2012-04-18 13:22:50 -04:00
Joey Hess
142bde13cd import juggling 2012-04-14 12:33:32 -04:00
Joey Hess
3642c72320 Renamed diskfree.c to avoid OSX case insensativity bug. 2012-04-13 11:26:39 -04:00
Joey Hess
6464a576cd allow add or del events to be ignored 2012-04-12 17:28:40 -04:00
Joey Hess
be4edbaaf1 allow excluding directories from being watched 2012-04-12 16:59:33 -04:00
Joey Hess
4ccc86669a don't fall over broken links 2012-04-12 16:46:57 -04:00
Joey Hess
d08a67a78e put in a warning so I remember to look at this 2012-04-12 15:48:59 -04:00
Joey Hess
1f34bf9acb add waitForTermination 2012-04-11 20:28:01 -04:00
Joey Hess
b133a76f96 recursive inotify thing
Recursive inotify has beaten me before, with its bad design and races,
but not this time! (I think.) This is able to follow the strongest
filesystem traffic I can throw at it, and robustly notices every file
add and delete. Mostly that's down to Haskell having a quite nice threaded
inotify library (that does its own buffering). A key insight was realizing
that the inotify directory add race could be dealt with by scanning for
files inside newly added directories.

TODO: Add support for freebsd/osx kqueue; see
http://hackage.haskell.org/package/kqueue

Can a git-annex-monitor be far off?
2012-04-11 20:09:38 -04:00
Joey Hess
62c69e7e25 Disable diskfree on kfreebsd, as I have a build failure on kfreebsd-i386 that is quite likely caused by it. 2012-04-07 15:50:34 -04:00
Joey Hess
42cc85a82f use struct statfs64 on OSX 2012-03-23 12:05:05 -04:00
Joey Hess
0f2052446f tweak 2012-03-22 23:02:20 -04:00
Joey Hess
6f514155f1 update 2012-03-22 23:02:20 -04:00
Joey Hess
d7d2fefbf2 break out kfreebsd
Now tested on linux and freebsd (amd64).
2012-03-22 17:32:47 -04:00
Joey Hess
e38a839a80 Rewrote free disk space checking code
Moving the portability handling into a small C library cleans up things
a lot, avoiding the pain of unpacking structs from inside haskell code.
2012-03-22 17:32:47 -04:00
Joey Hess
a362c46b70 fun with symbols
Nothing at all on hackage is using <&&> or <||>.

(Also, <&&> should short-circuit on failure.)
2012-03-17 00:38:40 -04:00
Joey Hess
771052a85e optimize monadic ||
(||) used applicative style runs both conditions rather than short
circuiting. Add an orM that properly short-circuits.
2012-03-16 12:28:17 -04:00
Joey Hess
b06336fa3a simplify 2012-03-16 02:12:56 -04:00
Joey Hess
c0c9991c9f nukes another 15 lines thanks to ifM 2012-03-15 20:39:25 -04:00
Joey Hess
60ab3d84e1 added ifM and nuked 11 lines of code
no behavior changes
2012-03-14 17:43:34 -04:00
Joey Hess
95a1f6b2ac check hook executability 2012-03-14 12:17:38 -04:00
Joey Hess
6fd0c0bfec move 2012-03-11 18:12:36 -04:00
Joey Hess
f9d44cccd9 perhaps more clear type 2012-03-10 11:38:38 -04:00
Joey Hess
10d9315b59 cleanup 2012-03-09 20:43:50 -04:00
Joey Hess
bca3fd65b9 fix key directory hash calculation code
Fix Key directory hash calculation code to behave as it did before version
3.20120227 when a key contains non-ascii.

The hash directories for a given Key are based on its md5sum.
Prior to ghc 7.4, Keys contained raw, undecoded bytes, so the md5sum was
taken of each byte in turn. With the ghc 7.4 filename encoding change,
keys contains decoded unicode characters (possibly with surrigates for
undecodable bytes). This changes the result of the md5sum, since the md5sum
used is pure haskell and supports unicode. And that won't do, as git-annex
will start looking in a different hash directory for the content of a key.

The surrigates are particularly bad, since that's essentially a ghc
implementation detail, so could change again at any time. Also, changing
the locale changes how the bytes are decoded, which can also change
the md5sum.

Symptoms would include things like:

* git annex fsck would complain that no copies existed of a file,
  despite its symlink pointing to the content that was locally present
* git annex fix would change the symlink to use the wrong hash
  directory.

Only WORM backend is likely to have been affected, since only it tends
to include much filename data (SHA1E could in theory also be affected).

I have not tried to support the hash directories used by git-annex versions
3.20120227 to 3.20120308, so things added with those versions with WORM
will require manual fixups. Sorry for the inconvenience!
2012-03-09 20:03:51 -04:00
Joey Hess
d6e77595ba factor out Utility.FileSystemEncoding 2012-03-09 19:08:10 -04:00
Joey Hess
789254747b refactor 2012-03-09 18:52:03 -04:00
Joey Hess
51338486dc Fix a bug in symlink calculation code, that triggered in rare cases where an annexed file is in a subdirectory that nearly matched to the .git/annex/object/xx/yy subdirectories.
This is a straight up pure-code stinker. The relative path calculation
looked for common subdirectories in the two paths, but failed to stop
after the paths diverged. When a later pair of subdirectories were the
same, the resulting relative path was wrong.

Added regression test for this.
2012-03-05 12:42:52 -04:00
Joey Hess
6c0155efb7 refactor 2012-02-20 15:22:21 -04:00
Joey Hess
a1e52f0ce5 hlint 2012-02-16 00:44:51 -04:00
Joey Hess
ecfcb41abe work around Network.Browser bug that converts a HEAD to a GET when following a redirect
The code explicitly switches from HEAD to GET for most redirects.
Possibly because someone misread a spec (which does require switching from
POST to GET for 303 redirects). Or possibly because the spec really is that
bad. Upstream bug: https://github.com/haskell/HTTP/issues/24

Since we absolutely don't want to download entire (large) files from
the web when checking that they exist with HEAD, I wrote my own redirect
follower, based closely on the one used by Network.Browser, but without
this misfeature.

Note that Network.Browser checks that the redirect url is a http url
and fails if not. I don't, because I want to not need to change this
code when it gets https support (related: I'm surprised to see it
doesn't support https yet..). The check does not seem security significant;
it doesn't support file:// urls for example. If a http url is redirected
to https, the Network.Browser will actually make a http connection again.
This could loop, but only up to 5 times.
2012-02-10 21:54:25 -04:00
Joey Hess
9030f68452 When checking that an url has a key, verify that the Content-Length, if available, matches the size of the key.
If there's no Content-Length, or the key has no size, this check is not
done, but it should happen most of the time, and protect against web
content that has changed.
2012-02-10 19:23:41 -04:00
Joey Hess
56470ce3e5 really fix foreign C functions filename encodings
GHC should probably export withFilePath.
2012-02-04 14:30:28 -04:00
Joey Hess
f1c7dc1212 fix touch and statfs to work on any files in any locale
Use withCAString rather than withCString.

XXX Actually, this only works in non-unicode locales when presented with
unicode characters. Help?
2012-02-04 12:44:51 -04:00
Joey Hess
44b115e0b1 Merge branch 'master' into ghc7.4
Conflicts:
	Utility/Misc.hs
2012-02-03 16:48:40 -04:00
Joey Hess
146c36ca54 IO exception rework
ghc 7.4 comaplains about use of System.IO.Error to catch exceptions.
Ok, use Control.Exception, with variants specialized to only catch IO
exceptions.
2012-02-03 16:47:24 -04:00
Joey Hess
d8fb97806c support all filename encodings with ghc 7.4
Under ghc 7.4, this seems to be able to handle all filename encodings
again. Including filename encodings that do not match the LANG setting.
I think this will not work with earlier versions of ghc, it uses some ghc
internals.

Turns out that ghc 7.4 has a special filesystem encoding that it uses when
reading/writing filenames (as FilePaths). This encoding is documented
to allow  "arbitrary undecodable bytes to be round-tripped through it".

So, to get FilePaths from eg, git ls-files, set the Handle that is reading
from git to use this encoding. Then things basically just work.

However, I have not found a way to make Text read using this encoding.
Text really does assume unicode. So I had to switch back to using String
when reading/writing data to git. Which is a pity, because it's some
percent slower, but at least it works.

Note that stdout and stderr also have to be set to this encoding, or
printing out filenames that contain undecodable bytes causes a crash.
IMHO this is a misfeature in ghc, that the user can pass you a filename,
which you can readFile, etc, but that default, putStr of filename may
cause a crash!

Git.CheckAttr gave me special trouble, because the filenames I got back
from git, after feeding them in, had further encoding breakage.
Rather than try to deal with that, I just zip up the input filenames
with the attributes. Which must be returned in the same order queried
for this to work.

Also of note is an apparent GHC bug I worked around in Git.CheckAttr. It
used to forkProcess and feed git from the child process.  Unfortunatly,
after this forkProcess, accessing the `files` variable from the parent
returns []. Not the value that was passed into the function. This screams
of a bad bug, that's clobbering a variable, but for now I just avoid
forkProcess there to work around it. That forkProcess was itself only added
because of a ghc bug, #624389. I've confirmed that the test case for that
bug doesn't reproduce it with ghc 7.4. So that's ok, except for the new ghc
bug I have not isolated and reported. Why does this simple bit of code
magnet the ghc bugs? :)

Also, the symlink touching code is currently broken, when used on utf-8
filenames in a non-utf-8 locale, or probably on any filename containing
undecodable bytes, and I temporarily commented it out.
2012-02-03 16:23:20 -04:00
Joey Hess
a964012fc3 switch to the strict state monad
I had not realized what a memory leak the lazy state monad could be,
although I have not seen much evidence of actual leaking in git-annex.
However, if running git-annex on a great many files, this could matter.

The additional Utility.State.changeState adds even more strictness,
avoiding a problem I saw in github-backup where repeatedly modifying
state built up a huge pile of thunks.
2012-01-29 22:55:06 -04:00
Joey Hess
ce5637498f remove Utility.Conditional and use IfElse
This drops the >>! and >>? with the nice low fixity. IfElse does have
undocumented >>=>>! and >>=>>? operators, but I deem that too fishy.
Anyway, using whenM and unlessM is easier; I sometimes mixed the operators
up.
2012-01-24 16:22:07 -04:00
Joey Hess
ba6088b249 rename readMaybe to readish
a stricter (but also partial) readMaybe is getting added to base
2012-01-23 17:00:10 -04:00
Joey Hess
5e172b43c4 a few things available elsewhere... 2012-01-23 16:57:45 -04:00