Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"<file> is not readable or exists" when using xcscope over TRAMP #20

Closed
Raphus-cucullatus opened this issue Jul 16, 2019 · 6 comments
Closed

Comments

@Raphus-cucullatus
Copy link

When using xcscope over TRAMP, the database can be found and the query results shown correctly. However, the results cannot be jumped to with a message "<file> is not readable or exists". It seems that xcscope tries the filename on my local machine.

More specifically,

  • I was at a file /scp:val17:/home/yf/src/qemu-git/migration/ram.c.
  • I used cscope-find-global-definition to find the definition of memory_global_dirty_log_start
  • The *cscope* buffer showed the global definition correctly
    Finding global definition: memory_global_dirty_log_start
    Database directory: /scp:val17:/home/yf/src/qemu-git/
    
    *** /home/yf/src/qemu-git/memory.c:
    memory_global_dirty_log_start[2568] void memory_global_dirty_log_start(void )
    
    Search complete.  Search time = 0.76 seconds.
  • But I could not jump to the entry. A message shows "/home/yf/src/qemu-git/memory.c is not readable or exists

It seems that xcscope tried the filename (/home/yf/src/qemu-git/memory.c) on my local machine instead on remote.

@dkogan
Copy link
Owner

dkogan commented Jul 16, 2019

Hi. Thanks for the report.

I'm somewhat mystified by this. xcscope has worked with TRAMP for years, and I use it this way all the time. Let's try to figure out what's going on before patching this.

First off, can you confirm that you're running xcscope.el from this repo (or from Debian or Ubuntu)? The copy the cscope project ships is ancient, and does not work with TRAMP.

If so, let's look at the properties on your end. In your *cscope* buffer put the point on the m in memory_global_dirty_log_start[2568] and hit C-u C-x =

A new window will open up, telling you things. Towards the end it should say something like

There are text properties here:
  cscope-file          "/scp:val17:......."

Do you see that? Specifically, the cscope-file property should contain the full TRAMP path. Does it?

@Raphus-cucullatus
Copy link
Author

  1. xcscope.el from MELPA (xcscope-20180426.712) was used. Though, I re-produced the issue using the xcscope.el from this repo (I used Emacs 25.2.2 and 26.2).

  2. C-u C-x = in my case shows

There are text properties here:
  cscope-file          "/home/yf/src/qemu-git/memory.c"
  cscope-fuzzy-search-text-regexp "void\\s-*memory\\s-*_\\s-*global\\s-*_\\s-*dirty\\s-*_\\s-*log\\s-*_\\s-*start\\s-*(\\s-*void\\s-*)"
  cscope-line-number   2568
  face                 cscope-function-face
  mouse-face           cscope-mouse-face

I see. I guess this issue is related to how the cscope database is generated. I use make cscope to generate the database. And it turns out absolute path is used for file names.

In this case, expand-file-name does not expand the "absolute" file name with the TRAMP prefix. So the "absolute" file name "(/home/yf/src/qemu-git/memory.c") is inserted in the text properties.

(expand-file-name file)

Therefore, my fix #21 does not work either. It only works when the file names are absolute. For relative file names, it produces "/scp:yf@val17:memory.c" which also leads to "is not readable or exists" :P

@dkogan
Copy link
Owner

dkogan commented Jul 17, 2019

OK. What does make cscope do? All my testing was done with indexing with C-c s I. This doesn't request absolute or relative, but rather does the default thing. You should try it to see what it does for you. And you should tell me what your command does so that I can test it here.

@Raphus-cucullatus
Copy link
Author

Raphus-cucullatus commented Jul 17, 2019

Sorry for insufficient information.

make cscope does:

rm -f "/home/yf/src/qemu-git"/cscope.*
find "/home/yf/src/qemu-git/" -name "*.[chsS]" -print > "/home/yf/src/qemu-git/cscope.files"
cscope -b -i"/home/yf/src/qemu-git/cscope.files"

The head of the cscope.files:

/home/yf/src/qemu-git/migration/xbzrle.h
/home/yf/src/qemu-git/migration/rdma.h
/home/yf/src/qemu-git/migration/channel.h
/home/yf/src/qemu-git/migration/socket.c
/home/yf/src/qemu-git/migration/qjson.h
/home/yf/src/qemu-git/migration/migration.h
/home/yf/src/qemu-git/migration/tls.h
/home/yf/src/qemu-git/migration/qemu-file-channel.h
/home/yf/src/qemu-git/migration/global_state.c
/home/yf/src/qemu-git/migration/fd.h

@dkogan
Copy link
Owner

dkogan commented Jul 17, 2019

Please try this patch:

diff --git a/xcscope.el b/xcscope.el
index e6f8a6b..539e5ad 100644
--- a/xcscope.el
+++ b/xcscope.el
@@ -2144,6 +2144,18 @@ concatenation of ARGS is returned"
   dir
   )
 
+
+(defun cscope--expand-file-name-with-absolute-remote (file)
+  "Returns an expanded filename, with the remote prefix.
+This is just like `expand-file-name', but will always contain the
+remote prefix if `default-directory' has one. `expand-file-name'
+will not do this if FILE is an absolute (but local) path"
+  (let ((file-expanded (expand-file-name file)))
+    (if (file-remote-p file-expanded)
+        file-expanded
+      (concat (or (file-remote-p default-directory) "")
+              file-expanded))))
+
 (defun cscope-construct-custom-options-list ()
   "Returns a list of cscope options defined by the
 cscope-option-* variables"
@@ -2361,7 +2373,7 @@ using the mouse."
                                                  str))
                           (cscope-insert-with-text-properties
                            str
-                           (expand-file-name file))
+                           (cscope--expand-file-name-with-absolute-remote file))
                           (insert "\n")))
 
                     (if cscope-first-match-point
@@ -2374,7 +2386,7 @@ using the mouse."
                      (cscope-make-entry-line function-name
                                              line-number
                                              line)
-                     (expand-file-name file)
+                     (cscope--expand-file-name-with-absolute-remote file)
                      line-number
                      line)
                     (insert "\n")

@Raphus-cucullatus
Copy link
Author

OK, it fixes this issue.

dkogan added a commit that referenced this issue Jul 23, 2019
Apparently this wasn't working if using absolute file names. Closes: #20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants