New upstream version 1.0.2
Sébastien Delafond
3 years ago
5 | 5 | # This program can be distributed under the terms of the GNU LGPL. |
6 | 6 | # See the file COPYING. |
7 | 7 | # |
8 | ||
9 | from __future__ import print_function | |
8 | 10 | |
9 | 11 | import os, sys |
10 | 12 | from errno import * |
11 | 13 | from stat import * |
12 | 14 | import fcntl |
15 | from threading import Lock | |
13 | 16 | # pull in some spaghetti to make this stuff work without fuse-py being installed |
14 | 17 | try: |
15 | 18 | import _find_fuse_parts |
165 | 168 | self.file = os.fdopen(os.open("." + path, flags, *mode), |
166 | 169 | flag2mode(flags)) |
167 | 170 | self.fd = self.file.fileno() |
171 | if hasattr(os, 'pread'): | |
172 | self.iolock = None | |
173 | else: | |
174 | self.iolock = Lock() | |
168 | 175 | |
169 | 176 | def read(self, length, offset): |
170 | self.file.seek(offset) | |
171 | return self.file.read(length) | |
177 | if self.iolock: | |
178 | self.iolock.acquire() | |
179 | try: | |
180 | self.file.seek(offset) | |
181 | return self.file.read(length) | |
182 | finally: | |
183 | self.iolock.release() | |
184 | else: | |
185 | return os.pread(self.fd, length, offset) | |
172 | 186 | |
173 | 187 | def write(self, buf, offset): |
174 | self.file.seek(offset) | |
175 | self.file.write(buf) | |
176 | return len(buf) | |
188 | if self.iolock: | |
189 | self.iolock.acquire() | |
190 | try: | |
191 | self.file.seek(offset) | |
192 | return self.file.write(buf) | |
193 | finally: | |
194 | self.iolock.release() | |
195 | else: | |
196 | return os.pwrite(self.fd, buf, offset) | |
177 | 197 | |
178 | 198 | def release(self, flags): |
179 | 199 | self.file.close() |
409 | 409 | static int |
410 | 410 | fsyncdir_func(const char *path, int datasync, struct fuse_file_info *fi) |
411 | 411 | { |
412 | #ifdef FIX_PATH_DECODING | |
413 | PROLOGUE( PYO_CALLWITHFI(fi, fsyncdir_cb, &Oi, &Path_AsDecodedUnicode, path, datasync) ) | |
414 | #else | |
412 | 415 | PROLOGUE( PYO_CALLWITHFI(fi, fsyncdir_cb, si, path, datasync) ) |
416 | #endif | |
413 | 417 | EPILOGUE |
414 | 418 | } |
415 | 419 | |
461 | 465 | { |
462 | 466 | PyObject *iter, *w; |
463 | 467 | |
468 | #ifdef FIX_PATH_DECODING | |
469 | PROLOGUE( PYO_CALLWITHFI(fi, readdir_cb, O&K, &Path_AsDecodedUnicode, path, off) ) | |
470 | #else | |
464 | 471 | PROLOGUE( PYO_CALLWITHFI(fi, readdir_cb, sK, path, off) ) |
472 | #endif | |
465 | 473 | #else |
466 | 474 | static int |
467 | 475 | readdir_func(const char *path, fuse_dirh_t buf, fuse_dirfil_t df) |
682 | 690 | #endif |
683 | 691 | { |
684 | 692 | #if PY_MAJOR_VERSION >= 3 |
693 | #ifdef FIX_PATH_DECODING | |
694 | PROLOGUE( PYO_CALLWITHFI(fi, write_cb, O&y#K, &Path_AsDecodedUnicode, path, buf, t, off) ) | |
695 | #else | |
685 | 696 | PROLOGUE( PYO_CALLWITHFI(fi, write_cb, sy#K, path, buf, t, off) ) |
697 | #endif | |
686 | 698 | #else |
687 | 699 | PROLOGUE( PYO_CALLWITHFI(fi, write_cb, ss#K, path, buf, t, off) ) |
688 | 700 | #endif |