Browse files

Make sure min is cast to size_t, add hacked-in directory support. Per…

…forms beautifully, though.
  • Loading branch information...
1 parent 088765a commit 18d1d7e92297a072ded1036e72334c968f550898 Chris Heald committed Feb 24, 2010
Showing with 26 additions and 6 deletions.
  1. +1 −0 SConstruct
  2. +4 −4 local_gridfile.cpp
  3. +11 −2 operations.cpp
  4. +10 −0 utils.h
View
1 SConstruct 100644 → 100755
@@ -13,6 +13,7 @@ if 'darwin' == os.sys.platform:
if os.uname()[2] == '10.0.0':
# Snow Leopard uses 64 bit inodes
fuse_lib += '_ino64'
+env.Append(CPPPATH=['/opt/mongo/include'], LIBPATH=['/opt/mongo/lib'])
conf = Configure( env )
libs = [ "mongoclient" , fuse_lib ]
View
8 local_gridfile.cpp 100644 → 100755
@@ -21,7 +21,7 @@ int LocalGridFile::write(const char *buf, size_t nbyte, off_t offset)
int buf_offset = offset % _chunkSize;
if(buf_offset) {
dest_buf += offset % _chunkSize;
- int to_write = min(nbyte - written,
+ int to_write = min<size_t>(nbyte - written,
(long unsigned int)(_chunkSize - buf_offset));
memcpy(dest_buf, buf, to_write);
written += to_write;
@@ -30,7 +30,7 @@ int LocalGridFile::write(const char *buf, size_t nbyte, off_t offset)
while(written < nbyte) {
dest_buf = _chunks[chunk_num];
- int to_write = min(nbyte - written,
+ int to_write = min<size_t>(nbyte - written,
(long unsigned int)_chunkSize);
memcpy(dest_buf, buf, to_write);
written += to_write;
@@ -50,11 +50,11 @@ int LocalGridFile::read(char* buf, size_t size, off_t offset)
while(len < size && chunk_num < _chunks.size()) {
const char* chunk = _chunks[chunk_num];
- size_t to_read = min((size_t)_chunkSize, size - len);
+ size_t to_read = min<size_t>((size_t)_chunkSize, size - len);
if(!len && offset) {
chunk += offset % _chunkSize;
- to_read = min(to_read,
+ to_read = min<size_t>(to_read,
(size_t)(_chunkSize - (offset % _chunkSize)));
}
View
13 operations.cpp 100644 → 100755
@@ -45,6 +45,7 @@ int gridfs_getattr(const char *path, struct stat *stbuf)
memset(stbuf, 0, sizeof(struct stat));
if(strcmp(path, "/") == 0) {
+ cout << "Returning stat for base dir: " << path;
stbuf->st_mode = S_IFDIR | 0777;
stbuf->st_nlink = 2;
return 0;
@@ -65,12 +66,20 @@ int gridfs_getattr(const char *path, struct stat *stbuf)
}
ScopedDbConnection sdc(gridfs_options.host);
+
GridFS gf(sdc.conn(), gridfs_options.db);
GridFile file = gf.findFile(path);
sdc.done();
- if(!file.exists()) {
- return -ENOENT;
+ if(!file.exists()) {
+ // HACK: Assumes that if the last part of the path has a '.' in it, it's the leaf of the path, and if we haven't found a match by now,
+ // give up and go home. This works just dandy as long as you avoid putting periods in your 'directory' names.
+ if(is_leaf(path)) {
+ return -ENOENT;
+ }
+ stbuf->st_mode = S_IFDIR | 0777;
+ stbuf->st_nlink = 2;
+ return 0;
}
stbuf->st_mode = S_IFREG | 0555;
View
10 utils.h 100644 → 100755
@@ -31,6 +31,16 @@ inline const char* fuse_to_mongo_path(const char* path)
}
}
+inline const bool is_leaf(const char* path) {
+ int pp = -1;
+ int sp = -1;
+ for(int i=0; i<strlen(path); i++) {
+ if(path[i] == '/') sp = i;
+ if(path[i] == '.') pp = i;
+ }
+ return pp > sp;
+}
+
inline time_t mongo_time_to_unix_time(unsigned long long mtime)
{
return mtime / 1000;

0 comments on commit 18d1d7e

Please sign in to comment.