Get rid of background mode under osx. Apparently fork and libmtp don't get along well under osx.

This commit is contained in:
Jason Ferrara 2012-05-09 23:07:37 +00:00
parent 91e28e675c
commit 852070556e
2 changed files with 14 additions and 42 deletions

View File

@ -25,7 +25,6 @@
#include <unistd.h>
#include <algorithm>
#include <magic.h>
#include <iostream>
@ -63,8 +62,6 @@ MtpDevice::MtpDevice(LIBMTP_raw_device_t& rawDevice)
{
MtpLibLock lock;
std::cout << "opening device" << std::endl;
m_mtpdevice = LIBMTP_Open_Raw_Device_Uncached(&rawDevice);
if (m_mtpdevice == 0)
throw MtpErrorCantOpenDevice();
@ -109,7 +106,6 @@ std::vector<MtpStorageInfo> MtpDevice::GetStorageDevices()
{
MtpLibLock lock;
std::cout << "get storage devices " << std::endl;
if (LIBMTP_Get_Storage(m_mtpdevice, LIBMTP_STORAGE_SORTBY_NOTSORTED))
{
CheckErrors(true);

View File

@ -68,9 +68,8 @@ RecursiveMutex globalLock;
return -EIO; \
}
int requestedBusLocation=-1;
int requestedDevnum=-1;
std::unique_ptr<MtpDevice> currentDevice;
MtpDevice* currentDevice;
MtpMetadataCache* metadataCache;
std::unique_ptr<MtpNode> getNode(const FilesystemPath& path)
@ -269,32 +268,6 @@ extern "C" int jmtpfs_statfs(const char *pathStr, struct statvfs *stat)
FUSE_ERROR_BLOCK_END
}
extern "C" void* jmtpfs_init(struct fuse_conn_info *conn)
{
currentDevice = 0;
ConnectedMtpDevices devices;
if (devices.NumDevices()==0)
{
std::cerr << "No mtp devices found." << std::endl;
throw std::runtime_error("No mtp devices found");
}
for(int i = 0; i<devices.NumDevices(); i++)
{
ConnectedDeviceInfo devInfo = devices.GetDeviceInfo(i);
if (((devInfo.bus_location == requestedBusLocation) &&
(devInfo.devnum == requestedDevnum)) ||
(requestedBusLocation == -1) || (requestedDevnum == -1))
{
currentDevice = devices.GetDevice(i);
break;
}
}
if (currentDevice == 0)
{
std::cerr << "Requested device not found" << std::endl;
throw std::runtime_error("Requested device not found");
}
}
struct jmtpfs_options
{
@ -323,6 +296,7 @@ static struct fuse_operations jmtpfs_oper = {
int main(int argc, char *argv[])
{
std::unique_ptr<MtpDevice> device;
std::unique_ptr<MtpMetadataCache> cache;
LIBMTP_Init();
@ -340,7 +314,6 @@ int main(int argc, char *argv[])
jmtpfs_oper.flush = jmtpfs_flush;
jmtpfs_oper.rename = jmtpfs_rename;
jmtpfs_oper.statfs = jmtpfs_statfs;
jmtpfs_oper.init = jmtpfs_init;
jmtpfs_options options;
@ -371,8 +344,8 @@ int main(int argc, char *argv[])
return 0;
}
requestedBusLocation=-1;
requestedDevnum=-1;
int requestedBusLocation=-1;
int requestedDevnum=-1;
if (options.device)
{
std::string devstr(options.device);
@ -402,7 +375,7 @@ int main(int argc, char *argv[])
}
else
{
bool foundDevice = 0;
currentDevice = 0;
ConnectedMtpDevices devices;
if (devices.NumDevices()==0)
{
@ -416,16 +389,16 @@ int main(int argc, char *argv[])
(devInfo.devnum == requestedDevnum)) ||
(requestedBusLocation == -1) || (requestedDevnum == -1))
{
foundDevice = true;
device = devices.GetDevice(i);
currentDevice = device.get();
break;
}
}
if (!foundDevice)
if (currentDevice == 0)
{
std::cerr << "Requested device not found" << std::endl;
return -1;
}
cache = std::unique_ptr<MtpMetadataCache>(new MtpMetadataCache);
metadataCache = cache.get();
}
@ -434,9 +407,12 @@ int main(int argc, char *argv[])
{
std::cout << "jmtpfs version: " << JMTPFS_VERSION << std::endl;
}
int result = fuse_main(args.argc, args.argv, &jmtpfs_oper, 0);
currentDevice.reset();
#ifdef __APPLE__
fuse_opt_add_arg(&args, "-f");
#endif
int result = fuse_main(args.argc, args.argv, &jmtpfs_oper, 0);
if (options.displayHelp)
{