added 1 changeset to branch 'refs/remotes/axeld-github/master' old head: acd512e9c64483a56d4fbec4a46d60ac13910fe4 new head: fcafaec6b5415ffc8191120161bea7b202118bf7 overview: https://github.com/axeld/haiku/compare/acd512e...fcafaec ---------------------------------------------------------------------------- fcafaec: mountvolume: open mounted images/volumes in Tracker. * This can be done from the command line using the new "-open" option. * When the application is invoked via Tracker, ie. by double clicking on an image, then it's being used implicitly. [ Axel Dörfler <axeld@xxxxxxxxxxxxxxxx> ] ---------------------------------------------------------------------------- Commit: fcafaec6b5415ffc8191120161bea7b202118bf7 Author: Axel Dörfler <axeld@xxxxxxxxxxxxxxxx> Date: Sun Mar 10 21:20:29 2013 UTC ---------------------------------------------------------------------------- 2 files changed, 40 insertions(+), 7 deletions(-) src/bin/Jamfile | 2 +- src/bin/mountvolume.cpp | 45 +++++++++++++++++++++++++++++++++++++++------ ---------------------------------------------------------------------------- diff --git a/src/bin/Jamfile b/src/bin/Jamfile index a06268a..ee517b1 100644 --- a/src/bin/Jamfile +++ b/src/bin/Jamfile @@ -6,7 +6,7 @@ SetSubDirSupportedPlatformsBeOSCompatible ; AddSubDirSupportedPlatforms libbe_test ; -UsePrivateHeaders app interface shared storage support usb ; +UsePrivateHeaders app interface shared storage support tracker usb ; UsePrivateSystemHeaders ; SubDirHdrs $(HAIKU_TOP) src add-ons kernel file_cache ; UseLibraryHeaders ncurses ; diff --git a/src/bin/mountvolume.cpp b/src/bin/mountvolume.cpp index b9bd217..43c4c5a 100644 --- a/src/bin/mountvolume.cpp +++ b/src/bin/mountvolume.cpp @@ -1,6 +1,6 @@ /* * Copyright 2005-2007 Ingo Weinhold, bonefish@xxxxxxxxxxxx - * Copyright 2005-2009 Axel Dörfler, axeld@xxxxxxxxxxxxxxxx + * Copyright 2005-2013 Axel Dörfler, axeld@xxxxxxxxxxxxxxxx * Copyright 2009 Jonas Sundström, jonas@xxxxxxxxxx * * All rights reserved. Distributed under the terms of the MIT License. @@ -27,6 +27,9 @@ #include <DiskDeviceList.h> #include <Partition.h> +#include <tracker_private.h> + + using std::set; using std::string; @@ -56,6 +59,7 @@ static const char* kUsage = " -alldos - mount all mountable DOS volumes\n" " -ro, -readonly - mount volumes read-only\n" " -u, -unmount <volume> - unmount the volume with the name <volume>\n" + " -open - opens the mounted volumes in Tracker\n" "\n" "[info]\n" " -p, -l - list all mounted and mountable volumes\n" @@ -116,6 +120,25 @@ size_string(int64 size) } +static status_t +open_in_tracker(BPartition* partition) +{ + BPath mountPoint; + status_t status = partition->GetMountPoint(&mountPoint); + if (status != B_OK) + return status; + + entry_ref ref; + status = get_ref_for_path(mountPoint.Path(), &ref); + if (status != B_OK) + return status; + + BMessage refs(B_REFS_RECEIVED); + refs.AddRef("refs", &ref); + return BMessenger(kTrackerSignature).SendMessage(&refs); +} + + // #pragma mark - @@ -127,7 +150,8 @@ struct MountVisitor : public BDiskDeviceVisitor { mountBFS(false), mountHFS(false), mountDOS(false), - readOnly(false) + readOnly(false), + openInTracker(false) { } @@ -184,7 +208,7 @@ struct MountVisitor : public BDiskDeviceVisitor { // mount/unmount if (mount) { status_t error = partition->Mount(NULL, - (readOnly ? B_MOUNT_READ_ONLY : 0)); + readOnly ? B_MOUNT_READ_ONLY : 0); if (!silent) { if (error >= B_OK) { BPath mountPoint; @@ -196,6 +220,8 @@ struct MountVisitor : public BDiskDeviceVisitor { name, strerror(error)); } } + if (openInTracker && error == B_OK) + open_in_tracker(partition); } else if (unmount) { status_t error = partition->Unmount(); if (!silent) { @@ -219,9 +245,10 @@ struct MountVisitor : public BDiskDeviceVisitor { bool mountHFS; bool mountDOS; bool readOnly; + bool openInTracker; }; -// PrintPartitionsVisitor + struct PrintPartitionsVisitor : public BDiskDeviceVisitor { PrintPartitionsVisitor() : listMountablePartitions(false), @@ -330,9 +357,10 @@ MountVolume::RefsReceived(BMessage* message) entry_ref ref; BPath path; - int32 argc = refCount + 1; + int32 argc = refCount + 2; char** argv = new char*[argc + 1]; argv[0] = strdup(kAppName); + argv[1] = strdup("-open"); for (int32 i = 0; i < refCount; i++) { message->FindRef("refs", i, &ref); @@ -341,7 +369,7 @@ MountVolume::RefsReceived(BMessage* message) fprintf(stderr, "Failed to get a path (%s) from entry (%s): %s\n", path.Path(), ref.name, strerror(status)); } - argv[1 + i] = strdup(path.Path()); + argv[2 + i] = strdup(path.Path()); } argv[argc] = NULL; @@ -385,6 +413,8 @@ MountVolume::ArgvReceived(int32 argc, char** argv) if (argi >= argc) print_usage_and_exit(true); mountVisitor.toUnmount.insert(argv[argi]); + } else if (strcmp(arg, "-open") == 0) { + mountVisitor.openInTracker = true; } else if (strcmp(arg, "-p") == 0 || strcmp(arg, "-l") == 0) { printPartitionsVisitor.listMountablePartitions = true; } else if (strcmp(arg, "-lh") == 0) { @@ -461,6 +491,9 @@ MountVolume::ArgvReceived(int32 argc, char** argv) } } if (status >= B_OK) { + if (mountVisitor.openInTracker) + open_in_tracker(partition); + // remove from list mountVisitor.toMount.erase(name); } else if (id >= 0)